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

40 lines
1.3 KiB
C#
Raw Normal View History

using System.Collections.Concurrent;
using System.Text.Json;
using HermesSocketLibrary.Requests.Messages;
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class GetTTSVoicesAck : IRequestAck
{
public string Name => "get_tts_voices";
private readonly User _user;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public GetTTSVoicesAck(User user, JsonSerializerOptions options, ILogger logger)
{
_user = user;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var voices = JsonSerializer.Deserialize<IEnumerable<VoiceDetails>>(json, _options);
if (voices == null)
{
_logger.Warning("Voices received is null.");
return;
}
if (!voices.Any())
{
_logger.Warning("Voices received is empty.");
return;
}
_user.VoicesAvailable = new ConcurrentDictionary<string, string>(voices.ToDictionary(e => e.Id, e => e.Name));
_logger.Information($"Fetched all available voices for TTS [count: {_user.VoicesAvailable.Count}]");
}
}
}