diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index dac9a36..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "Dependencies/CoreOSC-VRC-UTF8"] - path = Dependencies/CoreOSC-VRC-UTF8 - url = https://github.com/VRCWizard/CoreOSC-VRC-UTF8.git diff --git a/ButterSTT.sln b/ButterSTT.sln index b87bc13..b88eb01 100644 --- a/ButterSTT.sln +++ b/ButterSTT.sln @@ -4,9 +4,7 @@ VisualStudioVersion = 17.6.33829.357 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ButterSTT", "ButterSTT\ButterSTT.csproj", "{C8328FE0-794A-4FCE-B8ED-82449F22C8BD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreOSC", "Dependencies\CoreOSC-VRC-UTF8\CoreOSC\CoreOSC.csproj", "{4919CC8D-D8F3-423F-944C-7E375D0E16EF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ButterSTT.Tests", "ButterSTT.Tests\ButterSTT.Tests.csproj", "{FCE266B7-2036-499B-92FB-263C8A39D570}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ButterSTT.Tests", "ButterSTT.Tests\ButterSTT.Tests.csproj", "{FCE266B7-2036-499B-92FB-263C8A39D570}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -18,10 +16,6 @@ Global {C8328FE0-794A-4FCE-B8ED-82449F22C8BD}.Debug|Any CPU.Build.0 = Debug|Any CPU {C8328FE0-794A-4FCE-B8ED-82449F22C8BD}.Release|Any CPU.ActiveCfg = Release|Any CPU {C8328FE0-794A-4FCE-B8ED-82449F22C8BD}.Release|Any CPU.Build.0 = Release|Any CPU - {4919CC8D-D8F3-423F-944C-7E375D0E16EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4919CC8D-D8F3-423F-944C-7E375D0E16EF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4919CC8D-D8F3-423F-944C-7E375D0E16EF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4919CC8D-D8F3-423F-944C-7E375D0E16EF}.Release|Any CPU.Build.0 = Release|Any CPU {FCE266B7-2036-499B-92FB-263C8A39D570}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FCE266B7-2036-499B-92FB-263C8A39D570}.Debug|Any CPU.Build.0 = Debug|Any CPU {FCE266B7-2036-499B-92FB-263C8A39D570}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/ButterSTT/ButterSTT.csproj b/ButterSTT/ButterSTT.csproj index c234df1..8c7f0c0 100644 --- a/ButterSTT/ButterSTT.csproj +++ b/ButterSTT/ButterSTT.csproj @@ -9,15 +9,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - diff --git a/ButterSTT/Config/STTConfig.cs b/ButterSTT/Config/STTConfig.cs index b35b4c5..c267d62 100644 --- a/ButterSTT/Config/STTConfig.cs +++ b/ButterSTT/Config/STTConfig.cs @@ -1,3 +1,4 @@ +using System.Net; using System.Text.Json.Serialization; namespace ButterSTT.Config @@ -16,10 +17,7 @@ public record STTConfig public int MicrophoneDeviceNumber { get; set; } = 0; [JsonPropertyName("osc_address")] - public string OSCAddress { get; set; } = "127.0.0.1"; - - [JsonPropertyName("osc_port")] - public int OSCPort { get; set; } = 9000; + public string OSCAddress { get; set; } = "127.0.0.1:9000"; [JsonPropertyName("osc_chatbox_ratelimit_s")] public double OSCChatboxRateLimitS { get; set; } = 1.3; @@ -39,7 +37,10 @@ public record STTConfig [JsonPropertyName("hard_word_time_s")] public double HardWordTimeS { get; set; } = 16.0; - // TimeSpan converters + // Converter utility properties + [JsonIgnore] + public IPEndPoint OSCEndpoint => IPEndPoint.Parse(OSCAddress); + [JsonIgnore] public TimeSpan OSCChatboxRateLimit => TimeSpan.FromSeconds(OSCChatboxRateLimitS); diff --git a/ButterSTT/MessageSystem/OSCMessageHandler.cs b/ButterSTT/MessageSystem/OSCMessageHandler.cs index d80a1c2..3f1a900 100644 --- a/ButterSTT/MessageSystem/OSCMessageHandler.cs +++ b/ButterSTT/MessageSystem/OSCMessageHandler.cs @@ -1,42 +1,32 @@ using System.Diagnostics; +using System.Net; using ButterSTT.Config; -using CoreOSC; +using LucHeart.CoreOSC; namespace ButterSTT.MessageSystem { - public class OSCMessageHandler + public class OSCMessageHandler : IDisposable { public TimeSpan RateLimit = STTConfig.Default.OSCChatboxRateLimit; public readonly MessageQueue MessageQueue; - private OSCHandler _oscHandler; + private OscSender _oscSender; private CancellationTokenSource? _messageLoopCancelSource; private Task? _messageLoop; private string _lastMessage = ""; - public OSCMessageHandler( - MessageQueue? messageQueue = null, - string? oscAddress = null, - int? oscPort = null - ) + public OSCMessageHandler(MessageQueue? messageQueue = null, IPEndPoint? ipEndPoint = null) { MessageQueue = messageQueue ?? new(); - _oscHandler = MakeOSCHandler(oscAddress, oscPort); + _oscSender = new(ipEndPoint ?? STTConfig.Default.OSCEndpoint); } - private static OSCHandler MakeOSCHandler(string? oscAddress = null, int? oscPort = null) + public void SetOSCEndpoint(IPEndPoint? ipEndPoint = null) { - return new( - oscAddress ?? STTConfig.Default.OSCAddress, - oscPort ?? STTConfig.Default.OSCPort - ); - } - - public void SetOSCEndpoint(string? oscAddress = null, int? oscPort = null) - { - _oscHandler = MakeOSCHandler(oscAddress, oscPort); + _oscSender.Dispose(); + _oscSender = new(ipEndPoint ?? STTConfig.Default.OSCEndpoint); } public bool IsLoopRunning => _messageLoop != null && !_messageLoop.IsCompleted; @@ -73,7 +63,7 @@ private async Task MessageLoop(CancellationToken cancelToken) { timer.Restart(); - SendMessage(); + await SendMessage(cancelToken); var timeout = RateLimit - timer.Elapsed; if (timeout.TotalMilliseconds > 0) @@ -81,7 +71,7 @@ private async Task MessageLoop(CancellationToken cancelToken) } } - private void SendMessage() + private async Task SendMessage(CancellationToken cancelToken = default) { try { @@ -89,17 +79,17 @@ private void SendMessage() if (string.IsNullOrWhiteSpace(message) || message == _lastMessage) return; - var chatbox = OSCHandler.MakeChatboxInput(message); + var chatbox = OSCUtils.MakeChatboxInput(message); if (MessageQueue.IsFinished) { // Just send the message, no more typing - _oscHandler.OSCSender.Send(chatbox); + await _oscSender.SendAsync(chatbox); } else { // Still typing the message... Show as typing! - _oscHandler.OSCSender.Send( - new OscBundle(0, chatbox, OSCHandler.MakeChatboxTyping(true)) + await _oscSender.SendAsync( + new OscBundle(0, chatbox, OSCUtils.MakeChatboxTyping(true)) ); } @@ -110,5 +100,11 @@ private void SendMessage() Console.WriteLine(ex); } } + + public void Dispose() + { + _oscSender.Dispose(); + GC.SuppressFinalize(this); + } } } diff --git a/ButterSTT/MessageSystem/OSCHandler.cs b/ButterSTT/MessageSystem/OSCUtils.cs similarity index 67% rename from ButterSTT/MessageSystem/OSCHandler.cs rename to ButterSTT/MessageSystem/OSCUtils.cs index 406fdde..78ac9ff 100644 --- a/ButterSTT/MessageSystem/OSCHandler.cs +++ b/ButterSTT/MessageSystem/OSCUtils.cs @@ -1,16 +1,9 @@ -using CoreOSC; +using LucHeart.CoreOSC; namespace ButterSTT.MessageSystem { - public class OSCHandler + public static class OSCUtils { - public readonly UDPSender OSCSender; - - public OSCHandler(string address = "127.0.0.1", int port = 9000) - { - OSCSender = new UDPSender(address, port); - } - public static OscMessage MakeChatboxTyping(bool isTyping) { return new OscMessage("/chatbox/typing", isTyping); diff --git a/ButterSTT/Program.cs b/ButterSTT/Program.cs index ac97b06..f7a1b43 100644 --- a/ButterSTT/Program.cs +++ b/ButterSTT/Program.cs @@ -45,11 +45,7 @@ WordTime = config.WordTime, HardWordTime = config.HardWordTime, }; -var oscHandler = new OSCMessageHandler( - messageQueue, - oscAddress: config.OSCAddress, - oscPort: config.OSCPort -) +using var oscHandler = new OSCMessageHandler(messageQueue, config.OSCEndpoint) { RateLimit = config.OSCChatboxRateLimit }; diff --git a/Dependencies/CoreOSC-VRC-UTF8 b/Dependencies/CoreOSC-VRC-UTF8 deleted file mode 160000 index 1caa13b..0000000 --- a/Dependencies/CoreOSC-VRC-UTF8 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1caa13b0176f510ff2ca3e42e1499453716963b5