hermes-server/Requests/UpdateTTSVoice.cs

39 lines
1.3 KiB
C#
Raw Normal View History

using HermesSocketLibrary.Requests.Messages;
using HermesSocketServer.Models;
using HermesSocketServer.Store;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests
{
public class UpdateTTSVoice : IRequest
{
public string Name => "update_tts_voice";
public string[] RequiredKeys => ["voice", "voiceId"];
private IStore<string, TTSVoice> _voices;
private ILogger _logger;
public UpdateTTSVoice(VoiceStore voices, ILogger logger)
{
_voices = voices;
_logger = logger;
}
2024-12-28 17:24:02 +00:00
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
2024-12-27 23:31:36 +00:00
string voiceName = data["voice"].ToString()!;
string voiceId = data["voiceid"].ToString()!;
var result = _voices.Set(voiceId, new TTSVoice()
{
2024-12-27 23:31:36 +00:00
Id = voiceId,
Name = voiceName
});
if (result)
{
2024-12-27 23:31:36 +00:00
_logger.Information($"Updated voice's [voice id: {voiceId}] name [new name: {voiceName}]");
2024-12-28 17:24:02 +00:00
return Task.FromResult(RequestResult.Successful(null));
}
2024-12-28 17:24:02 +00:00
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
}
}
}