From 0a00a107766ad1e6ded83755b552ee3d2b323fc2 Mon Sep 17 00:00:00 2001 From: VigersRay Date: Thu, 25 Jul 2024 00:51:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D1=83=D0=B4=D0=B8=D0=BE=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B8=20=D0=B2=20=D1=80=D0=B0=D0=B4=D0=B8?= =?UTF-8?q?=D0=BE=20=D1=87=D0=B0=D1=82=D0=B5=20=D1=82=D0=B5=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D1=8C=20=D0=B2=D0=BE=D1=81=D0=BF=D1=80=D0=BE=D0=B8=D0=B7?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D1=8F=D1=82=D1=81=D1=8F=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=B5=D0=B4=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_Sunrise/TTS/HumanoidProfileEditor.TTS.cs | 21 +++++------ Content.Client/_Sunrise/TTS/TTSSystem.cs | 37 +++++++++++++------ Resources/Changelog/ChangelogSunrise.yml | 11 ++++++ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Content.Client/_Sunrise/TTS/HumanoidProfileEditor.TTS.cs b/Content.Client/_Sunrise/TTS/HumanoidProfileEditor.TTS.cs index d36b1446bd..9b86a3f52f 100644 --- a/Content.Client/_Sunrise/TTS/HumanoidProfileEditor.TTS.cs +++ b/Content.Client/_Sunrise/TTS/HumanoidProfileEditor.TTS.cs @@ -2,7 +2,6 @@ using Content.Client._Sunrise.TTS; using Content.Shared._Sunrise.TTS; using Content.Shared.Preferences; -using Content.Sunrise.Interfaces.Shared; namespace Content.Client.Lobby.UI; @@ -24,10 +23,10 @@ public sealed partial class HumanoidProfileEditor SetVoice(_voiceList[args.Id].ID); }; - VoicePlayButton.OnPressed += _ => PlayPreviewTTS(); + VoicePlayButton.OnPressed += _ => PlayPreviewTts(); } - private void UpdateTTSVoicesControls() + private void UpdateTtsVoicesControls() { if (Profile is null) return; @@ -49,12 +48,12 @@ public sealed partial class HumanoidProfileEditor if (_sponsorsMgr is null) continue; - if (voice.SponsorOnly && _sponsorsMgr != null && - !_sponsorsMgr.GetClientPrototypes().Contains(voice.ID)) - { - VoiceButton.SetItemDisabled(VoiceButton.GetIdx(i), true); - VoiceButton.SetItemText(VoiceButton.GetIdx(i), $"{name} [СПОНСОР]"); // Sunrise-edit - } + if (!voice.SponsorOnly || _sponsorsMgr == null || + _sponsorsMgr.GetClientPrototypes().Contains(voice.ID)) + continue; + + VoiceButton.SetItemDisabled(VoiceButton.GetIdx(i), true); + VoiceButton.SetItemText(VoiceButton.GetIdx(i), $"{name} [СПОНСОР]"); // Sunrise-edit } var voiceChoiceId = _voiceList.FindIndex(x => x.ID == Profile.Voice); @@ -65,11 +64,11 @@ public sealed partial class HumanoidProfileEditor } } - private void PlayPreviewTTS() + private void PlayPreviewTts() { if (Profile is null) return; - _entManager.System().RequestPreviewTTS(Profile.Voice); + _entManager.System().RequestPreviewTts(Profile.Voice); } } diff --git a/Content.Client/_Sunrise/TTS/TTSSystem.cs b/Content.Client/_Sunrise/TTS/TTSSystem.cs index 8078952c7f..fcc8a3af58 100644 --- a/Content.Client/_Sunrise/TTS/TTSSystem.cs +++ b/Content.Client/_Sunrise/TTS/TTSSystem.cs @@ -20,6 +20,7 @@ public sealed class TTSSystem : EntitySystem [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IResourceManager _res = default!; [Dependency] private readonly AudioSystem _audio = default!; + [Dependency] private readonly SharedAudioSystem _sharedAudio = default!; [Dependency] private readonly IResourceCache _resourceCache = default!; [Dependency] private readonly IDependencyCollection _dependencyCollection = default!; @@ -31,11 +32,16 @@ public sealed class TTSSystem : EntitySystem private float _radioVolume; private int _fileIdx; private float _volumeAnnounce; - private EntityUid _announcementUid = EntityUid.Invalid; - private Queue _announceQueue = new(); + private Queue _ttsQueue = new(); private (EntityUid Entity, AudioComponent Component)? _currentPlaying; + public sealed class QueuedTts(byte[] data, SoundSpecifier? announcementSound = null) + { + public byte[] Data = data; + public SoundSpecifier? AnnouncementSound = announcementSound; + } + public override void Initialize() { _sawmill = Logger.GetSawmill("tts"); @@ -58,7 +64,7 @@ public sealed class TTSSystem : EntitySystem _contentRoot.Dispose(); } - public void RequestPreviewTTS(string voiceId) + public void RequestPreviewTts(string voiceId) { RaiseNetworkEvent(new RequestPreviewTTSEvent(voiceId)); } @@ -88,29 +94,28 @@ public sealed class TTSSystem : EntitySystem if (_volumeAnnounce == 0) return; - _announceQueue.Enqueue(ev); + var entry = new QueuedTts(ev.Data, ev.AnnouncementSound); + + _ttsQueue.Enqueue(entry); } private void PlayNextInQueue() { - if (_announceQueue.Count == 0) + if (_ttsQueue.Count == 0) { return; } - var ev = _announceQueue.Dequeue(); - - if (_announcementUid == EntityUid.Invalid) - _announcementUid = Spawn(null); + var entry = _ttsQueue.Dequeue(); var volume = SharedAudioSystem.GainToVolume(_volumeAnnounce); var finalParams = AudioParams.Default.WithVolume(volume); - if (ev.AnnouncementSound != null) + if (entry.AnnouncementSound != null) { - _currentPlaying = _audio.PlayGlobal(ev.AnnouncementSound, _announcementUid, finalParams.AddVolume(-5f)); + _currentPlaying = _audio.PlayGlobal(_sharedAudio.GetSound(entry.AnnouncementSound), new EntityUid(), finalParams.AddVolume(-5f)); } - _currentPlaying = PlayTTSBytes(ev.Data, _announcementUid, finalParams, true); + _currentPlaying = PlayTTSBytes(entry.Data, null, finalParams, true); } private void OnPlayTTS(PlayTTSEvent ev) @@ -120,6 +125,14 @@ public sealed class TTSSystem : EntitySystem if (volume == 0) return; + if (ev.IsRadio) + { + var entry = new QueuedTts(ev.Data); + + _ttsQueue.Enqueue(entry); + return; + } + volume = SharedAudioSystem.GainToVolume(volume * ev.VolumeModifier); var audioParams = AudioParams.Default.WithVolume(volume); diff --git a/Resources/Changelog/ChangelogSunrise.yml b/Resources/Changelog/ChangelogSunrise.yml index 450d475a19..df2233170d 100644 --- a/Resources/Changelog/ChangelogSunrise.yml +++ b/Resources/Changelog/ChangelogSunrise.yml @@ -1945,3 +1945,14 @@ type: Fix id: 146 time: '2024-07-24T21:47:55.955101+00:00' +- author: VigersRay + changes: + - message: "\u041E\u0437\u0432\u0443\u0447\u043A\u0430 \u0440\u0430\u0434\u0438\u043E\ + \ \u0447\u0430\u0442\u0430 \u0442\u0435\u043F\u0435\u0440\u044C \u0432\u043E\ + \u0441\u043F\u0440\u043E\u0438\u0437\u0432\u043E\u0434\u0438\u0442\u0441\u044F\ + \ \u0432 \u043E\u0447\u0435\u0440\u0435\u0434\u0438 \u043A\u0430\u043A \u043E\ + \u043F\u043E\u0432\u0435\u0449\u0435\u043D\u0438\u044F \u0441\u0442\u0430\u043D\ + \u0446\u0438\u0438." + type: Tweak + id: 147 + time: '2024-07-24T21:50:55.257309+00:00'