Skip to content

Commit

Permalink
hacky support for sapi5 and coqui voices to use from readaloud
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatehi committed May 7, 2023
1 parent 30854a9 commit f5419be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import time
from functools import wraps
import sapi5
import coqui

def timeit(func):
@wraps(func)
Expand All @@ -40,11 +41,13 @@ def index():
{"voiceName": "English-US.Female-1", "lang": "en", "gender": "Female"},
{"voiceName": "English-US.Male-1", "lang": "en", "gender": "Male"},
{"voiceName": "English-US-RadTTS.Female-1", "lang": "en", "gender": "Female"},
{"voiceName": "English-US-RadTTS.Male-1", "lang": "en", "gender": "Male"}
{"voiceName": "English-US-RadTTS.Male-1", "lang": "en", "gender": "Male"},
{"voiceName": "Persian-IR.Female-1", "lang": "fa", "gender": "Female"}
]
RIVA_VOICES = [voice["voiceName"] for voice in VOICES]
VOICES.extend(voice for voice in sapi5.voices())
SAPI5_VOICES = [voice["voiceName"] for voice in VOICES if voice["voiceName"] not in RIVA_VOICES]
COQUI_VOICES = ["Persian-IR.Female-1"]

@app.route('/voices')
def voices():
Expand All @@ -54,7 +57,9 @@ def tts_requests_from_http_request():
data = request.json
voice_name = data.get("voice", "English-US.Female-1")
output_list = []
if voice_name in SAPI5_VOICES:
if voice_name in COQUI_VOICES:
output_list.append({ "coqui": True, "voice": voice_name, "text": data["text"] })
elif voice_name in SAPI5_VOICES:
# sapi5 freaks out on multiline inputs so let's split on newlines.
for text in data["text"].split("\n"):
text = text.strip()
Expand Down Expand Up @@ -188,6 +193,9 @@ def tts_streaming_generator(reqs, sample_rate_hz, output_format, output_codec):
if "sapi5" in req:
responses_define_input_sample_rate = True
responses = [sapi5.synthesize(req["text"], req["voice"])]
elif "coqui" in req:
responses_define_input_sample_rate = True
responses = [coqui.synthesize(req["text"])]
else:
responses = [synthesize_with_retry(**req)]

Expand Down
13 changes: 13 additions & 0 deletions coqui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requests

url = "http://localhost:5001/synthesize"
class AudioResponse:
def __init__(self, audio, sample_rate_hz):
self.audio = audio
self.sample_rate_hz = sample_rate_hz

def synthesize(text):
payload = {"text": text}
response = requests.post(url, json=payload)
return AudioResponse(response.content, 24000)

0 comments on commit f5419be

Please sign in to comment.