Аудиозаписи в радио чате теперь воспроизводятся в очереди.
This commit is contained in:
parent
f4081b90fe
commit
0a00a10776
3 changed files with 46 additions and 23 deletions
|
|
@ -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<TTSSystem>().RequestPreviewTTS(Profile.Voice);
|
||||
_entManager.System<TTSSystem>().RequestPreviewTts(Profile.Voice);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<AnnounceTtsEvent> _announceQueue = new();
|
||||
private Queue<QueuedTts> _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);
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue