Fix tts settings (#1774)

This commit is contained in:
CrazyCat2048 2024-01-18 13:25:39 +03:00 • committed by GitHub
parent 02725c0882
commit 49dedfbef2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View file

@ -24,6 +24,16 @@ public sealed class TTSSystem : EntitySystem
private readonly MemoryContentRoot _contentRoot = new();
private static readonly ResPath Prefix = ResPath.Root / "TTS";
/// <summary>
/// Reducing the volume of the TTS when whispering. Will be converted to logarithm.
/// </summary>
private const float WhisperFade = 4f;
/// <summary>
/// The volume at which the TTS sound will not be heard.
/// </summary>
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;
}
}

View file

@ -1,4 +1,4 @@
- type: ttsVoice
- type: ttsVoice
id: Aidar
name: tts-voice-name-aidar
sex: Male