Added voice selection, username filter and word filter from hermes

This commit is contained in:
Tom
2024-01-05 10:07:41 +00:00
parent 8845757c29
commit 9cd6725570
10 changed files with 339 additions and 180 deletions

View File

@ -1,8 +1,10 @@
using System;
using TwitchChatTTS.Hermes;
public class HermesClient {
private Account account;
private string key;
private WebHelper _web;
public string Id { get => account?.id; }
public string Username { get => account?.username; }
@ -15,23 +17,73 @@ public class HermesClient {
}
key = File.ReadAllText(".token")?.Trim();
WebHelper.AddHeader("x-api-key", key);
_web = new WebHelper();
_web.AddHeader("x-api-key", key);
}
public async Task UpdateHermesAccount() {
account = await WebHelper.GetJson<Account>("https://hermes.goblincaves.com/api/account");
ValidateKey();
account = await _web.GetJson<Account>("https://hermes.goblincaves.com/api/account");
}
public async Task<TwitchBotToken> FetchTwitchBotToken() {
if (string.IsNullOrWhiteSpace(key)) {
throw new InvalidOperationException("Hermes API key not provided.");
}
ValidateKey();
var token = await WebHelper.GetJson<TwitchBotToken>("https://hermes.goblincaves.com/api/token/bot");
var token = await _web.GetJson<TwitchBotToken>("https://hermes.goblincaves.com/api/token/bot");
if (token == null) {
throw new Exception("Failed to fetch Twitch API token from Hermes.");
}
return token;
}
public async Task<IEnumerable<TTSUsernameFilter>> FetchTTSUsernameFilters() {
ValidateKey();
var filters = await _web.GetJson<IEnumerable<TTSUsernameFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/users");
if (filters == null) {
throw new Exception("Failed to fetch TTS username filters from Hermes.");
}
return filters;
}
public async Task<string> FetchTTSDefaultVoice() {
ValidateKey();
var data = await _web.GetJson<TTSVoice>("https://hermes.goblincaves.com/api/settings/tts/default");
if (data == null) {
throw new Exception("Failed to fetch TTS default voice from Hermes.");
}
return data.label;
}
public async Task<IEnumerable<TTSVoice>> FetchTTSEnabledVoices() {
ValidateKey();
var voices = await _web.GetJson<IEnumerable<TTSVoice>>("https://hermes.goblincaves.com/api/settings/tts");
if (voices == null) {
throw new Exception("Failed to fetch TTS enabled voices from Hermes.");
}
return voices;
}
public async Task<IEnumerable<TTSWordFilter>> FetchTTSWordFilters() {
ValidateKey();
var filters = await _web.GetJson<IEnumerable<TTSWordFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/words");
if (filters == null) {
throw new Exception("Failed to fetch TTS word filters from Hermes.");
}
return filters;
}
private void ValidateKey() {
if (string.IsNullOrWhiteSpace(key)) {
throw new InvalidOperationException("Hermes API key not provided.");
}
}
}

View File

@ -0,0 +1,5 @@
public class TTSUsernameFilter {
public string username { get; set; }
public string tag { get; set; }
public string userId { get; set; }
}

View File

@ -0,0 +1,6 @@
public class TTSVoice {
public string label { get; set; }
public int value { get; set; }
public string gender { get; set; }
public string language { get; set; }
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TwitchChatTTS.Hermes
{
public class TTSWordFilter
{
public string id { get; set; }
public string search { get; set; }
public string replace { get; set; }
public string userId { get; set; }
public bool IsRegex { get; set; }
public TTSWordFilter() {
IsRegex = true;
}
}
}