|
|
|
@ -2,6 +2,7 @@ import random
|
|
|
|
|
import requests
|
|
|
|
|
from requests.exceptions import JSONDecodeError
|
|
|
|
|
from utils import settings
|
|
|
|
|
from utils.voice import check_ratelimit
|
|
|
|
|
|
|
|
|
|
voices = [
|
|
|
|
|
"Brian",
|
|
|
|
@ -42,16 +43,20 @@ class StreamlabsPolly:
|
|
|
|
|
voice = str(settings.config["settings"]["tts"]["streamlabs_polly_voice"]).capitalize()
|
|
|
|
|
body = {"voice": voice, "text": text, "service": "polly"}
|
|
|
|
|
response = requests.post(self.url, data=body)
|
|
|
|
|
try:
|
|
|
|
|
voice_data = requests.get(response.json()["speak_url"])
|
|
|
|
|
with open(filepath, "wb") as f:
|
|
|
|
|
f.write(voice_data.content)
|
|
|
|
|
except (KeyError, JSONDecodeError):
|
|
|
|
|
if not check_ratelimit(response):
|
|
|
|
|
self.run(text, filepath, random_voice)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
if response.json()["error"] == "No text specified!":
|
|
|
|
|
raise ValueError("Please specify a text to convert to speech.")
|
|
|
|
|
voice_data = requests.get(response.json()["speak_url"])
|
|
|
|
|
with open(filepath, "wb") as f:
|
|
|
|
|
f.write(voice_data.content)
|
|
|
|
|
except (KeyError, JSONDecodeError):
|
|
|
|
|
print("Error occurred calling Streamlabs Polly")
|
|
|
|
|
try:
|
|
|
|
|
if response.json()["error"] == "No text specified!":
|
|
|
|
|
raise ValueError("Please specify a text to convert to speech.")
|
|
|
|
|
except (KeyError, JSONDecodeError):
|
|
|
|
|
print("Error occurred calling Streamlabs Polly")
|
|
|
|
|
|
|
|
|
|
def randomvoice(self):
|
|
|
|
|
return random.choice(self.voices)
|
|
|
|
|