Skip to content

Instantly share code, notes, and snippets.

@spencerkittleson
Created January 26, 2023 23:05
Show Gist options
  • Save spencerkittleson/7cf4c194518e9205443ddebde636cda7 to your computer and use it in GitHub Desktop.
Save spencerkittleson/7cf4c194518e9205443ddebde636cda7 to your computer and use it in GitHub Desktop.
Mimic3Service
namespace UserTriggerTextToSpeech
{
public class Mimic3Service
{
private static readonly HttpClient _client = new();
private readonly Uri _url = new("http://127.0.0.1:59125");
public Mimic3Service() {
}
public async Task<Stream> ConvertTts(string text) {
await CheckInstance();
var result = await _client.PostAsync($"{_url}/api/tts", new StringContent(text));
return await result.Content.ReadAsStreamAsync();
}
private async Task CheckInstance() {
var result = await _client.GetAsync(_url);
if (!result.IsSuccessStatusCode) {
throw new Exception("Mimic3 web server is not found. https://github.com/MycroftAI/mimic3 . Or https://hub.docker.com/r/mycroftai/mimic3 then `docker run -p 59125:59125 mycroftai/mimic3`");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment