mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
@@ -87,6 +87,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
LobbyVolumeSlider,
|
||||
InterfaceVolumeSlider,
|
||||
AnnouncerVolumeSlider,
|
||||
TtsVolumeSlider, // WD EDIT
|
||||
|
||||
LobbyMusicCheckBox,
|
||||
RestartSoundsCheckBox,
|
||||
@@ -127,7 +128,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
_cfg.SetCVar(CCVars.LobbyMusicVolume, LobbyVolumeSlider.Value / 100f * ContentAudioSystem.LobbyMultiplier);
|
||||
_cfg.SetCVar(CCVars.InterfaceVolume, InterfaceVolumeSlider.Value / 100f * ContentAudioSystem.InterfaceMultiplier);
|
||||
_cfg.SetCVar(CCVars.AnnouncerVolume, AnnouncerVolumeSlider.Value / 100f * ContentAudioSystem.AnnouncerMultiplier);
|
||||
_cfg.SetCVar(WhiteCVars.TtsVolume, TtsVolumeSlider.Value / 100f * ContentAudioSystem.TTSMultiplier); // WD EDIT
|
||||
_cfg.SetCVar(WhiteCVars.TTSVolume, TtsVolumeSlider.Value / 100f * ContentAudioSystem.TTSMultiplier); // WD EDIT
|
||||
|
||||
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
||||
|
||||
@@ -154,7 +155,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
LobbyVolumeSlider.Value = _cfg.GetCVar(CCVars.LobbyMusicVolume) * 100f / ContentAudioSystem.LobbyMultiplier;
|
||||
InterfaceVolumeSlider.Value = _cfg.GetCVar(CCVars.InterfaceVolume) * 100f / ContentAudioSystem.InterfaceMultiplier;
|
||||
AnnouncerVolumeSlider.Value = _cfg.GetCVar(CCVars.AnnouncerVolume) * 100f / ContentAudioSystem.AnnouncerMultiplier;
|
||||
TtsVolumeSlider.Value = _cfg.GetCVar(WhiteCVars.TtsVolume) * 100f / ContentAudioSystem.TTSMultiplier; // WD EDIT
|
||||
TtsVolumeSlider.Value = _cfg.GetCVar(WhiteCVars.TTSVolume) * 100f / ContentAudioSystem.TTSMultiplier; // WD EDIT
|
||||
|
||||
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||
|
||||
@@ -183,6 +184,8 @@ namespace Content.Client.Options.UI.Tabs
|
||||
Math.Abs(InterfaceVolumeSlider.Value - _cfg.GetCVar(CCVars.InterfaceVolume) * 100f / ContentAudioSystem.InterfaceMultiplier) < 0.01f;
|
||||
var isAnnouncerVolumeSame =
|
||||
Math.Abs(AnnouncerVolumeSlider.Value - _cfg.GetCVar(CCVars.AnnouncerVolume) * 100f / ContentAudioSystem.AnnouncerMultiplier) < 0.01f;
|
||||
var isTtsVolumeSame =
|
||||
Math.Abs(TtsVolumeSlider.Value - _cfg.GetCVar(WhiteCVars.TTSVolume) * 100f / ContentAudioSystem.TTSMultiplier) < 0.01f; // WD EDIT
|
||||
|
||||
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||
@@ -193,7 +196,7 @@ namespace Content.Client.Options.UI.Tabs
|
||||
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame
|
||||
&& isAmbientMusicVolumeSame && isAmbientSoundsSame && isLobbySame && isRestartSoundsSame && isEventSame
|
||||
&& isAnnouncerDisableMultipleSoundsSame && isAdminSoundsSame && isLobbyVolumeSame
|
||||
&& isInterfaceVolumeSame && isAnnouncerVolumeSame;
|
||||
&& isInterfaceVolumeSame && isAnnouncerVolumeSame && isTtsVolumeSame; // WD EDIT
|
||||
ApplyButton.Disabled = isEverythingSame;
|
||||
ResetButton.Disabled = isEverythingSame;
|
||||
MasterVolumeLabel.Text =
|
||||
@@ -210,6 +213,8 @@ namespace Content.Client.Options.UI.Tabs
|
||||
Loc.GetString("ui-options-volume-percent", ("volume", InterfaceVolumeSlider.Value / 100));
|
||||
AnnouncerVolumeLabel.Text =
|
||||
Loc.GetString("ui-options-volume-percent", ("volume", AnnouncerVolumeSlider.Value / 100));
|
||||
TtsVolumeLabel.Text =
|
||||
Loc.GetString("ui-options-volume-percent", ("volume", TtsVolumeSlider.Value / 100)); // WD EDIT
|
||||
AmbienceSoundsLabel.Text = ((int)AmbienceSoundsSlider.Value).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public sealed class TTSSystem : EntitySystem
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_cfg.OnValueChanged(WhiteCVars.TtsVolume, OnTtsVolumeChanged, true);
|
||||
_cfg.OnValueChanged(WhiteCVars.TTSVolume, OnTtsVolumeChanged, true);
|
||||
|
||||
SubscribeNetworkEvent<PlayTTSEvent>(OnPlayTTS);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public sealed class TTSSystem : EntitySystem
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_cfg.UnsubValueChanged(WhiteCVars.TtsVolume, OnTtsVolumeChanged);
|
||||
_cfg.UnsubValueChanged(WhiteCVars.TTSVolume, OnTtsVolumeChanged);
|
||||
ClearQueues();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
@@ -51,14 +52,21 @@ public sealed class TTSManager
|
||||
/// <returns>OGG audio bytes</returns>
|
||||
public async Task<byte[]?> ConvertTextToSpeech(string speaker, string text, string pitch, string rate, string? effect = null)
|
||||
{
|
||||
var url = _cfg.GetCVar(WhiteCVars.TtsApiUrl);
|
||||
var url = _cfg.GetCVar(WhiteCVars.TTSApiUrl);
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
_sawmill.Log(LogLevel.Error, nameof(TTSManager), "TTS Api url not specified");
|
||||
return null;
|
||||
}
|
||||
|
||||
var maxCacheSize = _cfg.GetCVar(WhiteCVars.TtsMaxCacheSize);
|
||||
var token = _cfg.GetCVar(WhiteCVars.TTSApiToken);
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
_sawmill.Log(LogLevel.Error, nameof(TTSManager), "TTS Api token not specified");
|
||||
return null;
|
||||
}
|
||||
|
||||
var maxCacheSize = _cfg.GetCVar(WhiteCVars.TTSMaxCache);
|
||||
WantedCount.Inc();
|
||||
var cacheKey = GenerateCacheKey(speaker, text);
|
||||
if (_cache.TryGetValue(cacheKey, out var data))
|
||||
@@ -70,6 +78,7 @@ public sealed class TTSManager
|
||||
|
||||
var body = new GenerateVoiceRequest
|
||||
{
|
||||
ApiToken = token,
|
||||
Text = text,
|
||||
Speaker = speaker,
|
||||
Pitch = pitch,
|
||||
@@ -77,13 +86,11 @@ public sealed class TTSManager
|
||||
Effect = effect
|
||||
};
|
||||
|
||||
var request = CreateRequestLink(url, body);
|
||||
|
||||
var reqTime = DateTime.UtcNow;
|
||||
try
|
||||
{
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
|
||||
var response = await _httpClient.GetAsync(request, cts.Token);
|
||||
var response = await _httpClient.PostAsJsonAsync(url, body, cts.Token);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception($"TTS request returned bad status code: {response.StatusCode}");
|
||||
|
||||
@@ -116,23 +123,6 @@ public sealed class TTSManager
|
||||
}
|
||||
}
|
||||
|
||||
private static string CreateRequestLink(string url, GenerateVoiceRequest body)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(url);
|
||||
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
|
||||
query["speaker"] = body.Speaker;
|
||||
query["text"] = body.Text;
|
||||
query["pitch"] = body.Pitch;
|
||||
query["rate"] = body.Rate;
|
||||
query["file"] = "1";
|
||||
query["ext"] = "ogg";
|
||||
if (body.Effect != null)
|
||||
query["effect"] = body.Effect;
|
||||
|
||||
uriBuilder.Query = query.ToString();
|
||||
return uriBuilder.ToString();
|
||||
}
|
||||
|
||||
public void ResetCache()
|
||||
{
|
||||
_cache.Clear();
|
||||
@@ -149,6 +139,9 @@ public sealed class TTSManager
|
||||
|
||||
private record GenerateVoiceRequest
|
||||
{
|
||||
[JsonPropertyName("api_token")]
|
||||
public string ApiToken { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = default!;
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_cfg.OnValueChanged(WhiteCVars.TtsEnabled, v => _isEnabled = v, true);
|
||||
_cfg.OnValueChanged(WhiteCVars.TtsApiUrl, url => _apiUrl = url, true);
|
||||
_cfg.OnValueChanged(WhiteCVars.TTSEnabled, v => _isEnabled = v, true);
|
||||
_cfg.OnValueChanged(WhiteCVars.TTSApiUrl, url => _apiUrl = url, true);
|
||||
|
||||
SubscribeLocalEvent<TTSComponent, EntitySpokeEvent>(OnEntitySpoke);
|
||||
|
||||
@@ -171,7 +171,7 @@ public sealed partial class TTSSystem : EntitySystem
|
||||
|
||||
private async void OnRequestTTS(MsgRequestTTS ev)
|
||||
{
|
||||
var url = _cfg.GetCVar(WhiteCVars.TtsApiUrl);
|
||||
var url = _cfg.GetCVar(WhiteCVars.TTSApiUrl);
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
return;
|
||||
|
||||
|
||||
@@ -34,23 +34,41 @@ public sealed class WhiteCVars
|
||||
/// <summary>
|
||||
/// if the TTS system enabled or not.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> TtsEnabled = CVarDef.Create("tts.enabled", true, CVar.SERVERONLY);
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<bool> TTSEnabled = CVarDef.Create("tts.enabled", true, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// URL of the TTS server API.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<string> TtsApiUrl = CVarDef.Create("tts.api_url", "", CVar.SERVERONLY);
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<string> TTSApiUrl = CVarDef.Create("tts.api_url", "", CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Auth token of the TTS server API.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<string> TTSApiToken =
|
||||
CVarDef.Create("tts.api_token", "", CVar.SERVERONLY | CVar.CONFIDENTIAL);
|
||||
|
||||
/// <summary>
|
||||
/// The volume of TTS playback.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> TtsVolume = CVarDef.Create("tts.volume", 0f, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<float> TTSVolume = CVarDef.Create("tts.volume", 0f, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// TTS Cache.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> TtsMaxCacheSize =
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<int> TTSMaxCache =
|
||||
CVarDef.Create("tts.max_cash_size", 200, CVar.SERVERONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// Amount of seconds before timeout for API
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly CVarDef<int> TTSApiTimeout =
|
||||
CVarDef.Create("tts.api_timeout", 5, CVar.SERVERONLY | CVar.ARCHIVE);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ tts-voice-name-asa = Ася
|
||||
tts-voice-name-valentain = Валентин
|
||||
tts-voice-name-chelsea = Челси
|
||||
tts-voice-name-anna = Анна
|
||||
tts-voice-name-jeanne = Джон
|
||||
tts-voice-name-jeanne = Жанна
|
||||
tts-voice-name-jasmin = Жасмин
|
||||
tts-voice-name-juelette = Джульета
|
||||
tts-voice-name-arina = Арина
|
||||
|
||||
Reference in New Issue
Block a user