Skip to content

Commit

Permalink
added support for browser proxy, add word global cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
krogenth committed Oct 4, 2024
1 parent 6ae8fff commit 1f8ecf1
Show file tree
Hide file tree
Showing 45 changed files with 1,090 additions and 381 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.2.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions OpenShock.VoiceRecognizer.Common/Enums/BrowserProxyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public enum BrowserProxyType
{
Chrome,
Edge,
Opera,
Firefox,
//Opera,
//Firefox,
};
6 changes: 3 additions & 3 deletions OpenShock.VoiceRecognizer.Common/Enums/RecognizerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenShock.VoiceRecognizer.Common.Enums;
public enum RecognizerType : int
{
Vosk,
Whisper,
Chrome,
Custom,
BrowserProxy,
//Whisper,
//Custom,
};
16 changes: 9 additions & 7 deletions OpenShock.VoiceRecognizer.Common/ReactiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ReactiveObject<T>(T defaultValue)
private bool _isInitialized = false;
private T _value = defaultValue;

public event EventHandler<ValueChangedEventArgs<T>>? ValueChanged;
public event EventHandler<ValueChangedEventArgs>? ValueChanged;

public T Value
{
Expand All @@ -33,7 +33,7 @@ public T Value

if (!oldIsInitialized || oldValue == null || !oldValue.Equals(_value))
{
ValueChanged?.Invoke(this, new ValueChangedEventArgs<T>(oldValue, value));
ValueChanged?.Invoke(this, new ValueChangedEventArgs(oldValue, value));
}
}
}
Expand All @@ -42,10 +42,12 @@ public static implicit operator T(ReactiveObject<T> obj)
{
return obj.Value;
}
}

public class ValueChangedEventArgs<T>(T oldValue, T newValue)
{
public T OldValue { get; } = oldValue;
public T NewValue { get; } = newValue;
public class ValueChangedEventArgs(T oldValue, T newValue)
{
public T OldValue { get; } = oldValue;
public T NewValue { get; } = newValue;
}
}


20 changes: 0 additions & 20 deletions OpenShock.VoiceRecognizer.Configuration/AudioConfigurationState.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ namespace OpenShock.VoiceRecognizer.Configuration;

public class BrowserProxyConfigurationState
{
public ReactiveObject<BrowserProxyType> Proxy { get; set; }
public ReactiveObject<BrowserProxyType> BrowserProxy { get; set; }
public ReactiveObject<int> ProxyPort { get; set; }

public BrowserProxyConfigurationState()
{
Proxy = new(BrowserProxyType.Chrome);
BrowserProxy = new(BrowserProxyType.Chrome);
ProxyPort = new(0);
}

public void LoadFileConfiguration(ConfigurationFileFormat configurationFileFormat)
{
Proxy.Value = configurationFileFormat.BrowserProxyType;
BrowserProxy.Value = configurationFileFormat.BrowserProxyType;
ProxyPort.Value = configurationFileFormat.BrowserProxyPort;
}

public void LoadDefaultConfiguration()
{
Proxy.Value = BrowserProxyType.Chrome;
BrowserProxy.Value = BrowserProxyType.Chrome;
ProxyPort.Value = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace OpenShock.VoiceRecognizer.Configuration;

public class ConfigurationFileFormat
{
public RecognizerType RecognizerType { get; set; } = RecognizerType.Vosk;
public string InputDeviceID { get; set; } = string.Empty;
public string VoskModelDirectory { get; set; } = string.Empty;
public int OscListenPort { get; set; } = 0;
Expand All @@ -21,15 +22,16 @@ public ConfigurationFileFormat() { }

public ConfigurationFileFormat(ConfigurationState state)
{
InputDeviceID = state.Audio.InputDeviceID.Value;
RecognizerType = state.General.Recognizer.Value;
InputDeviceID = state.General.InputDeviceID.Value;
VoskModelDirectory = state.Vosk.ModelDirectory.Value;
OscListenPort = state.OSC.ListenPort.Value;
CollarType = state.Shock.CollarType.Value;
CollarType = state.General.CollarType.Value;
Words = state.Shock.Words.Value;
OpenShockAPIKey = state.OpenShock.APIKey.Value;
OpenShockDeviceID = state.OpenShock.DeviceID.Value;
OpenShockShockerID = state.OpenShock.ShockerID.Value;
BrowserProxyType = state.BrowserProxy.Proxy.Value;
BrowserProxyType = state.BrowserProxy.BrowserProxy.Value;
BrowserProxyPort = state.BrowserProxy.ProxyPort.Value;
}

Expand Down
8 changes: 4 additions & 4 deletions OpenShock.VoiceRecognizer.Configuration/ConfigurationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ConfigurationState
{
private readonly string _fileLocation = $"{AppDomain.CurrentDomain.BaseDirectory}config.json";

public AudioConfigurationState Audio { get; }
public GeneralConfigurationState General { get; }
public VoskConfigurationState Vosk { get; }
public OSCConfigurationState OSC { get; }
public ShockConfigurationState Shock { get; }
Expand All @@ -15,7 +15,7 @@ public class ConfigurationState

private ConfigurationState()
{
Audio = new();
General = new();
Vosk = new();
OSC = new();
Shock = new();
Expand All @@ -39,7 +39,7 @@ private void LoadConfigurationStateFromFile()
{
if (ConfigurationFileFormat.TryLoad(_fileLocation, out ConfigurationFileFormat? configurationFileFormat))
{
Audio.LoadFileConfiguration(configurationFileFormat!);
General.LoadFileConfiguration(configurationFileFormat!);
Vosk.LoadFileConfiguration(configurationFileFormat!);
OSC.LoadFileConfiguration(configurationFileFormat!);
Shock.LoadFileConfiguration(configurationFileFormat!);
Expand All @@ -50,7 +50,7 @@ private void LoadConfigurationStateFromFile()

private void LoadDefaultConfigurationState()
{
Audio.LoadDefaultConfiguration();
General.LoadDefaultConfiguration();
Vosk.LoadDefaultConfiguration();
OSC.LoadDefaultConfiguration();
Shock.LoadDefaultConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using OpenShock.VoiceRecognizer.Common;
using OpenShock.VoiceRecognizer.Common.Audio;
using OpenShock.VoiceRecognizer.Common.Enums;

namespace OpenShock.VoiceRecognizer.Configuration;

public class GeneralConfigurationState
{
public ReactiveObject<RecognizerType> Recognizer { get; private set; }
public ReactiveObject<ShockCollarType> CollarType { get; private set; }
public ReactiveObject<string> InputDeviceID { get; private set; }

public GeneralConfigurationState()
{
Recognizer = new(RecognizerType.Vosk);
CollarType = new(ShockCollarType.OpenShock);
InputDeviceID = new(string.Empty);
}

public void LoadFileConfiguration(ConfigurationFileFormat configurationFileFormat)
{
Recognizer.Value = configurationFileFormat.RecognizerType;
CollarType.Value = configurationFileFormat.CollarType;
InputDeviceID.Value = configurationFileFormat.InputDeviceID;
}

public void LoadDefaultConfiguration()
{
CollarType.Value = ShockCollarType.OpenShock;
InputDeviceID.Value = AudioDevices.GetInputAudioDevices().First().ID;
}
}
15 changes: 4 additions & 11 deletions OpenShock.VoiceRecognizer.Configuration/ShockConfigurationState.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
using System.Collections.ObjectModel;
using OpenShock.VoiceRecognizer.Common;
using OpenShock.VoiceRecognizer.Common.Enums;
using OpenShock.VoiceRecognizer.Utility.Common;

namespace OpenShock.VoiceRecognizer.Configuration;

public class ShockConfigurationState
{
public ReactiveObject<ShockCollarType> CollarType { get; private set; }
public ReactiveObject<ObservableCollection<WordRecognition>> Words { get; private set; }

public ShockConfigurationState()
{
CollarType = new(ShockCollarType.OpenShock);
Words = new([]);
}

public void LoadFileConfiguration(ConfigurationFileFormat configurationFileFormat)
{
CollarType.Value = configurationFileFormat.CollarType;
public void LoadFileConfiguration(ConfigurationFileFormat configurationFileFormat) =>
Words.Value = configurationFileFormat.Words;
}

public void LoadDefaultConfiguration()
{
CollarType.Value = ShockCollarType.OpenShock;
public void LoadDefaultConfiguration() =>
Words.Value = [];
}
}

public class WordRecognition
Expand All @@ -45,5 +36,7 @@ public class WordRecognition
public ushort MinDuration { get; set; }
public ushort MaxDuration { get; set; }
public string DurationRange => $"{MinDuration} - {MaxDuration}";
public double Cooldown { get; set; }
public string CooldownStr => $"{Cooldown}";
public bool Active { get; set; }
}
Loading

0 comments on commit 1f8ecf1

Please sign in to comment.