[Fix] TTS announcement volume fix (#344)
This commit is contained in:
@@ -100,7 +100,10 @@ public sealed class TTSSystem : EntitySystem
|
||||
|
||||
private void OnPlayTTS(PlayTTSEvent ev)
|
||||
{
|
||||
if (!TryCreateAudioSource(ev.Data, out var source))
|
||||
var volume = 0f;
|
||||
if (ev.BoostVolume)
|
||||
volume = 5f;
|
||||
if (!TryCreateAudioSource(ev.Data, out var source, volume))
|
||||
return;
|
||||
|
||||
var stream = new AudioStream(GetEntity(ev.Uid), source);
|
||||
@@ -112,7 +115,7 @@ public sealed class TTSSystem : EntitySystem
|
||||
RaiseNetworkEvent(new RequestTTSEvent(text));
|
||||
}
|
||||
|
||||
private bool TryCreateAudioSource(byte[] data, [NotNullWhen(true)] out IAudioSource? source)
|
||||
private bool TryCreateAudioSource(byte[] data, [NotNullWhen(true)] out IAudioSource? source, float volume = 0f)
|
||||
{
|
||||
var dataStream = new MemoryStream(data) { Position = 0 };
|
||||
var audioStream = _audioSystem.LoadAudioOggVorbis(dataStream);
|
||||
@@ -122,7 +125,7 @@ public sealed class TTSSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
source.Volume = _volume;
|
||||
source.Volume = volume == 0f ? _volume : volume;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Light.Components;
|
||||
@@ -91,23 +92,23 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
|
||||
// Get closest emergency light
|
||||
var entity = entities.First();
|
||||
var range = 100f;
|
||||
var range = new Vector2(100f);
|
||||
|
||||
foreach (var item in entities)
|
||||
{
|
||||
var itemSource = _xforms.GetWorldPosition(Transform(item));
|
||||
var playerSource = _xforms.GetWorldPosition(Transform(player.AttachedEntity.Value));
|
||||
|
||||
var distance = playerSource.Length() - itemSource.Length();
|
||||
var distance = playerSource - itemSource;
|
||||
|
||||
if (range > distance)
|
||||
if (range.Length() > distance.Length())
|
||||
{
|
||||
range = distance;
|
||||
entity = item;
|
||||
}
|
||||
}
|
||||
|
||||
RaiseNetworkEvent(new PlayTTSEvent(GetNetEntity(entity), soundData), Filter.SinglePlayer(player),
|
||||
RaiseNetworkEvent(new PlayTTSEvent(GetNetEntity(entity), soundData, true), Filter.SinglePlayer(player),
|
||||
false);
|
||||
}
|
||||
}
|
||||
@@ -125,7 +126,7 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
|
||||
var soundData = await GenerateTTS(ev.Uid, ev.Text, protoVoice.Speaker);
|
||||
if (soundData != null)
|
||||
RaiseNetworkEvent(new PlayTTSEvent(GetNetEntity(ev.Uid), soundData), Filter.SinglePlayer(session), false);
|
||||
RaiseNetworkEvent(new PlayTTSEvent(GetNetEntity(ev.Uid), soundData, false), Filter.SinglePlayer(session), false);
|
||||
}
|
||||
|
||||
private async void OnEntitySpoke(EntityUid uid, TTSComponent component, EntitySpokeEvent args)
|
||||
@@ -152,7 +153,7 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
var soundData = await GenerateTTS(uid, message, protoVoice.Speaker);
|
||||
if (soundData is null)
|
||||
return;
|
||||
var ttsEvent = new PlayTTSEvent(GetNetEntity(uid), soundData);
|
||||
var ttsEvent = new PlayTTSEvent(GetNetEntity(uid), soundData, false);
|
||||
|
||||
// Say
|
||||
if (args.ObfuscatedMessage is null)
|
||||
@@ -175,7 +176,7 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
var obfSoundData = await GenerateTTS(uid, chosenWhisperText, protoVoice.Speaker);
|
||||
if (obfSoundData is null)
|
||||
return;
|
||||
var obfTtsEvent = new PlayTTSEvent(GetNetEntity(uid), obfSoundData);
|
||||
var obfTtsEvent = new PlayTTSEvent(GetNetEntity(uid), obfSoundData, false);
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var sourcePos = _xforms.GetWorldPosition(xformQuery.GetComponent(uid), xformQuery);
|
||||
var receptions = Filter.Pvs(uid).Recipients;
|
||||
|
||||
@@ -8,10 +8,12 @@ public sealed class PlayTTSEvent : EntityEventArgs
|
||||
{
|
||||
public NetEntity Uid { get; }
|
||||
public byte[] Data { get; }
|
||||
public bool BoostVolume { get; }
|
||||
|
||||
public PlayTTSEvent(NetEntity uid, byte[] data)
|
||||
public PlayTTSEvent(NetEntity uid, byte[] data, bool boostVolume)
|
||||
{
|
||||
Uid = uid;
|
||||
Data = data;
|
||||
BoostVolume = boostVolume;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user