diff --git a/Content.Client/Corvax/TTS/TTSSystem.cs b/Content.Client/Corvax/TTS/TTSSystem.cs index 14301df2e09..da0a58e15c2 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); } @@ -64,24 +65,26 @@ private void OnTtsVolumeChanged(float volume) private void OnPlayTTS(PlayTTSEvent ev) { - _sawmill.Debug($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity"); - - var volume = AdjustVolume(ev.IsWhisper); + _sawmill.Verbose($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity"); 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)) + .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); @@ -98,4 +101,9 @@ private float AdjustVolume(bool isWhisper) return volume; } + + private float AdjustDistance(bool isWhisper) + { + return isWhisper ? SharedChatSystem.WhisperMuffledRange : SharedChatSystem.VoiceRange; + } } 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.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 { 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";