last fixes

This commit is contained in:
EnefFlow
2023-05-08 14:55:45 +03:00
committed by Aviu00
parent 5be8c373b4
commit 1753d52885
3 changed files with 11 additions and 7 deletions

View File

@@ -41,7 +41,7 @@ public sealed class TTSManager
private readonly HttpClient _httpClient = new();
private ISawmill _sawmill = default!;
private readonly Dictionary<string, byte[]> _cache = new();
private readonly Dictionary<string, byte[]?> _cache = new();
public void Initialize()
{
@@ -55,7 +55,7 @@ public sealed class TTSManager
/// <param name="text">SSML formatted text</param>
/// <returns>OGG audio bytes</returns>
/// <exception cref="Exception">Throws if url or token CCVar not set or http request failed</exception>
public async Task<byte[]> ConvertTextToSpeech(string speaker, string text, string pitch, string rate)
public async Task<byte[]?> ConvertTextToSpeech(string speaker, string text, string pitch, string rate)
{
var url = _cfg.GetCVar(WhiteCVars.TTSApiUrl);
var maxCacheSize = _cfg.GetCVar(WhiteCVars.TTSMaxCacheSize);
@@ -111,14 +111,14 @@ public sealed class TTSManager
catch (TaskCanceledException)
{
RequestTimings.WithLabels("Timeout").Observe((DateTime.UtcNow - reqTime).TotalSeconds);
_sawmill.Error($"Timeout of request generation new sound for '{text}' speech by '{speaker}' speaker");
throw new Exception("TTS request timeout");
_sawmill.Warning($"Timeout of request generation new sound for '{text}' speech by '{speaker}' speaker");
return null;
}
catch (Exception e)
{
RequestTimings.WithLabels("Error").Observe((DateTime.UtcNow - reqTime).TotalSeconds);
_sawmill.Error($"Failed of request generation new sound for '{text}' speech by '{speaker}' speaker\n{e}");
throw new Exception("TTS request failed");
_sawmill.Warning($"Failed of request generation new sound for '{text}' speech by '{speaker}' speaker\n{e}");
return null;
}
}

View File

@@ -43,6 +43,10 @@ public sealed partial class TTSSystem : EntitySystem
private async void OnRequestTTS(MsgRequestTTS ev)
{
var url = _cfg.GetCVar(WhiteCVars.TTSApiUrl);
if (string.IsNullOrWhiteSpace(url))
return;
if (!_playerManager.TryGetSessionByChannel(ev.MsgChannel, out var session) ||
!_prototypeManager.TryIndex<TTSVoicePrototype>(ev.VoiceId, out var protoVoice))
return;

View File

@@ -39,7 +39,7 @@ public sealed class TTSPitchRateSystem : EntitySystem
pitchRate[0] = "high";
pitchRate[1] = "slow";
}
else if (humanoid.SkinColor.R >= 0.6) // Niggers
else if (humanoid.SkinColor.R >= 0.6)
{
pitchRate[0] = "x-low";
pitchRate[1] = "medium";