From 7acb137e0c712496fbdf3414c49f1f0525d01569 Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:09:50 +0300 Subject: [PATCH 1/4] Move chat voice range info to Shared --- Content.Server/Chat/Systems/ChatSystem.cs | 8 +++++--- Content.Shared/Chat/SharedChatSystem.cs | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Content.Server/Chat/Systems/ChatSystem.cs b/Content.Server/Chat/Systems/ChatSystem.cs index 69b7f6f7969..5bddb295119 100644 --- a/Content.Server/Chat/Systems/ChatSystem.cs +++ b/Content.Server/Chat/Systems/ChatSystem.cs @@ -58,9 +58,11 @@ public sealed partial class ChatSystem : SharedChatSystem [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly ReplacementAccentSystem _wordreplacement = default!; - public const int VoiceRange = 10; // how far voice goes in world units - public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units - public const int WhisperMuffledRange = 5; // how far whisper goes at all, in world units + // Corvax-TTS-Start: Moved from Server to Shared + // public const int VoiceRange = 10; // how far voice goes in world units + // public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units + // public const int WhisperMuffledRange = 5; // how far whisper goes at all, in world units + // Corvax-TTS-End public const string DefaultAnnouncementSound = "/Audio/Corvax/Announcements/announce.ogg"; // Corvax-Announcements public const string CentComAnnouncementSound = "/Audio/Corvax/Announcements/centcomm.ogg"; // Corvax-Announcements diff --git a/Content.Shared/Chat/SharedChatSystem.cs b/Content.Shared/Chat/SharedChatSystem.cs index a20d649d238..aca7f0404b5 100644 --- a/Content.Shared/Chat/SharedChatSystem.cs +++ b/Content.Shared/Chat/SharedChatSystem.cs @@ -22,6 +22,11 @@ public abstract class SharedChatSystem : EntitySystem public const char AdminPrefix = ']'; public const char WhisperPrefix = ','; public const char DefaultChannelKey = 'р'; // Corvax-Localization + // Corvax-TTS-Start: Moved from Server to Shared + public const int VoiceRange = 10; // how far voice goes in world units + public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units + public const int WhisperMuffledRange = 5; // how far whisper goes at all, in world units + // Corvax-TTS-End [ValidatePrototypeId] public const string CommonChannel = "Common"; From fddf29e6716e2f9ae7470a0d124c382826614f8e Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:10:46 +0300 Subject: [PATCH 2/4] Bypass cache manager and play raw resource --- Content.Client/Corvax/TTS/TTSSystem.cs | 32 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Content.Client/Corvax/TTS/TTSSystem.cs b/Content.Client/Corvax/TTS/TTSSystem.cs index 14301df2e09..6ccb8e8cb0f 100644 --- a/Content.Client/Corvax/TTS/TTSSystem.cs +++ b/Content.Client/Corvax/TTS/TTSSystem.cs @@ -1,11 +1,12 @@ -using Content.Shared.Corvax.CCCVars; +using Content.Shared.Chat; +using Content.Shared.Corvax.CCCVars; using Content.Shared.Corvax.TTS; +using Robust.Client.Audio; using Robust.Client.ResourceManagement; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Configuration; using Robust.Shared.ContentPack; -using Robust.Shared.Player; using Robust.Shared.Utility; namespace Content.Client.Corvax.TTS; @@ -17,8 +18,8 @@ namespace Content.Client.Corvax.TTS; public sealed class TTSSystem : EntitySystem { [Dependency] private readonly IConfigurationManager _cfg = default!; - [Dependency] private readonly IResourceCache _resourceCache = default!; - [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly IResourceManager _res = default!; + [Dependency] private readonly AudioSystem _audio = default!; private ISawmill _sawmill = default!; private readonly MemoryContentRoot _contentRoot = new(); @@ -40,7 +41,7 @@ public sealed class TTSSystem : EntitySystem public override void Initialize() { _sawmill = Logger.GetSawmill("tts"); - _resourceCache.AddRoot(Prefix, _contentRoot); + _res.AddRoot(Prefix, _contentRoot); _cfg.OnValueChanged(CCCVars.TTSVolume, OnTtsVolumeChanged, true); SubscribeNetworkEvent(OnPlayTTS); } @@ -66,28 +67,30 @@ private void OnPlayTTS(PlayTTSEvent ev) { _sawmill.Debug($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity"); - var volume = AdjustVolume(ev.IsWhisper); - var filePath = new ResPath($"{_fileIdx++}.ogg"); _contentRoot.AddOrUpdateFile(filePath, ev.Data); - var audioParams = AudioParams.Default.WithVolume(volume); - var soundPath = new SoundPathSpecifier(Prefix / filePath, audioParams); + var audioResource = new AudioResource(); + audioResource.Load(IoCManager.Instance!, Prefix / filePath); + + var audioParams = AudioParams.Default + .WithVolume(AdjustVolume(ev.IsWhisper, 1f)) + .WithMaxDistance(AdjustDistance(ev.IsWhisper)); if (ev.SourceUid != null) { var sourceUid = GetEntity(ev.SourceUid.Value); - _audio.PlayEntity(soundPath, Filter.Local(), sourceUid, false, audioParams); + _audio.PlayEntity(audioResource.AudioStream, sourceUid, audioParams); } else { - _audio.PlayGlobal(soundPath, Filter.Local(), false); + _audio.PlayGlobal(audioResource.AudioStream, audioParams); } _contentRoot.RemoveFile(filePath); } - private float AdjustVolume(bool isWhisper) + private float AdjustVolume(bool isWhisper, float distance) { var volume = MinimalVolume + SharedAudioSystem.GainToVolume(_volume); @@ -98,4 +101,9 @@ private float AdjustVolume(bool isWhisper) return volume; } + + private float AdjustDistance(bool isWhisper) + { + return isWhisper ? SharedChatSystem.WhisperMuffledRange : SharedChatSystem.VoiceRange; + } } From 551721c50e2786e85c3a6c1641613d8775f55e36 Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:11:05 +0300 Subject: [PATCH 3/4] Make TTS logs Verbose level --- Content.Client/Corvax/TTS/TTSSystem.cs | 2 +- Content.Server/Corvax/TTS/TTSManager.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Content.Client/Corvax/TTS/TTSSystem.cs b/Content.Client/Corvax/TTS/TTSSystem.cs index 6ccb8e8cb0f..f5069d6d0e6 100644 --- a/Content.Client/Corvax/TTS/TTSSystem.cs +++ b/Content.Client/Corvax/TTS/TTSSystem.cs @@ -65,7 +65,7 @@ private void OnTtsVolumeChanged(float volume) private void OnPlayTTS(PlayTTSEvent ev) { - _sawmill.Debug($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity"); + _sawmill.Verbose($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity"); var filePath = new ResPath($"{_fileIdx++}.ogg"); _contentRoot.AddOrUpdateFile(filePath, ev.Data); diff --git a/Content.Server/Corvax/TTS/TTSManager.cs b/Content.Server/Corvax/TTS/TTSManager.cs index 792e1cdf8a8..2696acc1408 100644 --- a/Content.Server/Corvax/TTS/TTSManager.cs +++ b/Content.Server/Corvax/TTS/TTSManager.cs @@ -68,11 +68,11 @@ public void Initialize() if (_cache.TryGetValue(cacheKey, out var data)) { ReusedCount.Inc(); - _sawmill.Debug($"Use cached sound for '{text}' speech by '{speaker}' speaker"); + _sawmill.Verbose($"Use cached sound for '{text}' speech by '{speaker}' speaker"); return data; } - _sawmill.Debug($"Generate new audio for '{text}' speech by '{speaker}' speaker"); + _sawmill.Verbose($"Generate new audio for '{text}' speech by '{speaker}' speaker"); var body = new GenerateVoiceRequest { From dffc62976675bfbcf7e9469e34cd33b69506a809 Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:15:44 +0300 Subject: [PATCH 4/4] Remove unused --- Content.Client/Corvax/TTS/TTSSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Client/Corvax/TTS/TTSSystem.cs b/Content.Client/Corvax/TTS/TTSSystem.cs index f5069d6d0e6..da0a58e15c2 100644 --- a/Content.Client/Corvax/TTS/TTSSystem.cs +++ b/Content.Client/Corvax/TTS/TTSSystem.cs @@ -74,7 +74,7 @@ private void OnPlayTTS(PlayTTSEvent ev) audioResource.Load(IoCManager.Instance!, Prefix / filePath); var audioParams = AudioParams.Default - .WithVolume(AdjustVolume(ev.IsWhisper, 1f)) + .WithVolume(AdjustVolume(ev.IsWhisper)) .WithMaxDistance(AdjustDistance(ev.IsWhisper)); if (ev.SourceUid != null) @@ -90,7 +90,7 @@ private void OnPlayTTS(PlayTTSEvent ev) _contentRoot.RemoveFile(filePath); } - private float AdjustVolume(bool isWhisper, float distance) + private float AdjustVolume(bool isWhisper) { var volume = MinimalVolume + SharedAudioSystem.GainToVolume(_volume);