47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Serilog;
|
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
|
{
|
|
public class CreateTTSVoiceAck : IRequestAck
|
|
{
|
|
public string Name => "create_tts_voice";
|
|
private readonly User _user;
|
|
private readonly ILogger _logger;
|
|
|
|
public CreateTTSVoiceAck(User user, ILogger logger)
|
|
{
|
|
_user = user;
|
|
_logger = logger;
|
|
}
|
|
|
|
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
|
{
|
|
if (requestData == null)
|
|
{
|
|
_logger.Warning("Request data is null.");
|
|
return;
|
|
}
|
|
|
|
var voice = requestData["voice"].ToString()!;
|
|
var voiceId = json;
|
|
if (string.IsNullOrEmpty(voice))
|
|
{
|
|
_logger.Warning("Voice name is invalid.");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(voiceId))
|
|
{
|
|
_logger.Warning("Voice Id is invalid.");
|
|
return;
|
|
}
|
|
if (_user.VoicesAvailable.TryGetValue(voiceId, out var voiceName))
|
|
{
|
|
_logger.Warning($"Voice Id already exists [voice id: {voiceId}][voice name: {voiceName}]");
|
|
return;
|
|
}
|
|
|
|
_user.VoicesAvailable.Add(voiceId, voice);
|
|
_logger.Information($"Created a new tts voice [voice: {voice}][id: {voiceId}]");
|
|
}
|
|
}
|
|
} |