hermes-client/Hermes/Socket/Requests/GetEnabledTTSVoices.cs

41 lines
1.3 KiB
C#

using System.Text.Json;
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class GetEnabledTTSVoicesAck : IRequestAck
{
public string Name => "get_enabled_tts_voices";
private readonly User _user;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public GetEnabledTTSVoicesAck(User user, JsonSerializerOptions options, ILogger logger)
{
_user = user;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var enabledTTSVoices = JsonSerializer.Deserialize<IEnumerable<string>>(json, _options);
if (enabledTTSVoices == null)
{
_logger.Warning("Failed to load enabled tts voices.");
return;
}
if (_user.VoicesEnabled == null)
_user.VoicesEnabled = enabledTTSVoices.ToHashSet();
else
{
_user.VoicesEnabled.Clear();
foreach (var voice in enabledTTSVoices)
_user.VoicesEnabled.Add(voice);
}
_logger.Information($"TTS voices [count: {_user.VoicesEnabled.Count}] have been enabled.");
}
}
}