Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanicArts committed Apr 29, 2023
2 parents 1e8efe3 + 73243bf commit 11b3ca7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions VRCOSC.Desktop/VRCOSC.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ApplicationIcon>game.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>0.0.0</Version>
<FileVersion>2023.428.0</FileVersion>
<FileVersion>2023.429.0</FileVersion>
<Title>VRCOSC</Title>
<Authors>VolcanicArts</Authors>
<Company>VolcanicArts</Company>
<Nullable>enable</Nullable>
<AssemblyVersion>2023.428.0</AssemblyVersion>
<AssemblyVersion>2023.429.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\VRCOSC.Game\VRCOSC.Game.csproj" />
Expand Down
5 changes: 0 additions & 5 deletions VRCOSC.Game/ChatBox/ChatBoxManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public bool SendEnabled
private DateTimeOffset nextValidTime;
private bool isClear;
private bool isLoaded;
private string lastText = string.Empty;

public void Load(Storage storage, GameManager gameManager, NotificationContainer notification)
{
Expand Down Expand Up @@ -194,7 +193,6 @@ public void Initialise(VRChatOscClient oscClient, Bindable<int> sendDelay, Dicti
nextValidTime = startTime;
isClear = true;
ModuleEnabledCache = moduleEnabledCache;
lastText = string.Empty;

Clips.ForEach(clip => clip.Initialise());
}
Expand Down Expand Up @@ -282,9 +280,6 @@ private void handleClip(Clip? clip)

private void sendText(string text)
{
if (text == lastText) return;

lastText = text;
oscClient.SendValues(VRChatOscConstants.ADDRESS_CHATBOX_INPUT, new List<object> { text, true, false });
}

Expand Down
11 changes: 11 additions & 0 deletions VRCOSC.Game/OSC/VRChat/VRChatOscClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class VRChatOscClient : OscClient
{
public Action<VRChatOscData>? OnParameterSent;
public Action<VRChatOscData>? OnParameterReceived;
private readonly Dictionary<string, List<object>> valuesCache = new();

public VRChatOscClient()
{
Expand All @@ -32,6 +33,16 @@ public VRChatOscClient()
private void sendData(OscData data)
{
data.PreValidate();

if (data.Address.StartsWith(VRChatOscConstants.ADDRESS_AVATAR_PARAMETERS_PREFIX))
{
if (valuesCache.TryGetValue(data.Address, out var previousValue))
{
if (data.Values.SequenceEqual(previousValue)) return;
}
}

valuesCache[data.Address] = data.Values;
SendByteData(data.Encode());
OnParameterSent?.Invoke(new VRChatOscData(data));
}
Expand Down
13 changes: 11 additions & 2 deletions VRCOSC.Modules/SpeechToText/SpeechToTextModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class SpeechToTextModule : ChatBoxModule
private readonly SpeechRecognitionEngine speechRecognitionEngine = new();
private VoskRecognizer? recogniser;
private bool readyToAccept;
private bool shouldAnalyse => readyToAccept && (!GetSetting<bool>(SpeechToTextSetting.FollowMute) || Player.IsMuted.GetValueOrDefault());
private bool listening;
private bool shouldAnalyse => readyToAccept && listening && (!GetSetting<bool>(SpeechToTextSetting.FollowMute) || Player.IsMuted.GetValueOrDefault());
private readonly object processingLock = new();
private byte[]? buffer;

Expand All @@ -40,6 +41,7 @@ protected override void CreateAttributes()
CreateSetting(SpeechToTextSetting.FollowMute, "Follow Mute", "Only run recognition when you're muted", false);

CreateParameter<bool>(SpeechToTextParameter.Reset, ParameterMode.Read, "VRCOSC/SpeechToText/Reset", "Reset", "Manually reset the state to idle to remove the generated text from the ChatBox");
CreateParameter<bool>(SpeechToTextParameter.Listen, ParameterMode.ReadWrite, "VRCOSC/SpeechToText/Listen", "Listen", "Whether Speech To Text is currently listening");

CreateVariable(SpeechToTextVariable.Text, "Text", "text");

Expand All @@ -63,6 +65,7 @@ protected override void OnModuleStart()

Log("Model loading...");
readyToAccept = false;
listening = true;

Task.Run(() =>
{
Expand All @@ -82,6 +85,7 @@ protected override void OnModuleStart()
SetChatBoxTyping(false);
SetVariableValue(SpeechToTextVariable.Text, string.Empty);
ChangeStateTo(SpeechToTextState.Idle);
SendParameter(SpeechToTextParameter.Listen, listening);
}

protected override void OnModuleStop()
Expand All @@ -107,6 +111,10 @@ protected override void OnBoolParameterReceived(Enum key, bool value)
ChangeStateTo(SpeechToTextState.Idle);
SetVariableValue(SpeechToTextVariable.Text, string.Empty);
break;

case SpeechToTextParameter.Listen:
listening = value;
break;
}
}

Expand Down Expand Up @@ -186,7 +194,8 @@ private enum SpeechToTextSetting

private enum SpeechToTextParameter
{
Reset
Reset,
Listen
}

private enum SpeechToTextState
Expand Down

0 comments on commit 11b3ca7

Please sign in to comment.