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