From 49dedfbef2989a2bb5904b85f7d7d0f2ea464a0d Mon Sep 17 00:00:00 2001
From: CrazyCat2048 <137882635+CrazyCat2048@users.noreply.github.com>
Date: Thu, 18 Jan 2024 13:25:39 +0300
Subject: [PATCH] Fix tts settings (#1774)
---
Content.Client/Corvax/TTS/TTSSystem.cs | 27 +++++++++++++++++++---
Resources/Prototypes/Corvax/tts-voices.yml | 2 +-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/Content.Client/Corvax/TTS/TTSSystem.cs b/Content.Client/Corvax/TTS/TTSSystem.cs
index 48093f4203..3e854113c3 100644
--- a/Content.Client/Corvax/TTS/TTSSystem.cs
+++ b/Content.Client/Corvax/TTS/TTSSystem.cs
@@ -24,6 +24,16 @@ public sealed class TTSSystem : EntitySystem
private readonly MemoryContentRoot _contentRoot = new();
private static readonly ResPath Prefix = ResPath.Root / "TTS";
+ ///
+ /// Reducing the volume of the TTS when whispering. Will be converted to logarithm.
+ ///
+ private const float WhisperFade = 4f;
+
+ ///
+ /// The volume at which the TTS sound will not be heard.
+ ///
+ private const float MinimalVolume = -10f;
+
private float _volume = 0.0f;
private int _fileIdx = 0;
@@ -56,15 +66,14 @@ public sealed class TTSSystem : EntitySystem
{
_sawmill.Debug($"Play TTS audio {ev.Data.Length} bytes from {ev.SourceUid} entity");
- var volume = _volume;
- if (ev.IsWhisper)
- volume -= 4;
+ 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);
+
if (ev.SourceUid != null)
{
var sourceUid = GetEntity(ev.SourceUid.Value);
@@ -77,4 +86,16 @@ public sealed class TTSSystem : EntitySystem
_contentRoot.RemoveFile(filePath);
}
+
+ private float AdjustVolume(bool isWhisper)
+ {
+ var volume = MinimalVolume + SharedAudioSystem.GainToVolume(_volume);
+
+ if (isWhisper)
+ {
+ volume -= SharedAudioSystem.GainToVolume(WhisperFade);
+ }
+
+ return volume;
+ }
}
diff --git a/Resources/Prototypes/Corvax/tts-voices.yml b/Resources/Prototypes/Corvax/tts-voices.yml
index 83693464dc..18ef00541f 100644
--- a/Resources/Prototypes/Corvax/tts-voices.yml
+++ b/Resources/Prototypes/Corvax/tts-voices.yml
@@ -1,4 +1,4 @@
-- type: ttsVoice
+- type: ttsVoice
id: Aidar
name: tts-voice-name-aidar
sex: Male