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? requestData) { var voices = JsonSerializer.Deserialize>(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(voices.ToDictionary(e => e.Id, e => e.Name)); _logger.Information($"Fetched all available voices for TTS [count: {_user.VoicesAvailable.Count}]"); } } }