Skip to content

Commit

Permalink
endpoint_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Dec 30, 2023
1 parent 3e5b205 commit 4e3c24b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ovos_tts_plugin_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class OVOSServerTTS(TTS):
public_servers_v2 = [
]
public_servers = [
"https://pipertts.ziggyai.online",
"https://tts.smartgic.io/piper"
Expand All @@ -13,6 +15,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, audio_ext="wav",
validator=OVOSServerTTSValidator(self))
self.host = self.config.get("host", None)
self.v2 = self.config.get("v2", False) # TODO - change to True once all servers update

def get_tts(self, sentence, wav_file, lang=None, voice=None):
lang = lang or self.lang
Expand All @@ -26,18 +29,25 @@ def get_tts(self, sentence, wav_file, lang=None, voice=None):
else:
servers = self.host
else:
servers = self.public_servers
random.shuffle(servers) # Spread the load among all public servers
if self.v2:
servers = self.public_servers_v2
else:
servers = self.public_servers
data = self._get_from_servers(params, sentence, servers)
with open(wav_file, "wb") as f:
f.write(data)
return wav_file, None

def _get_from_servers(self, params: dict, sentence: str, servers: list):
random.shuffle(servers) # Spread the load among all public servers
for url in servers:
try:
r = requests.get(f'{url}/synthesize/{sentence}',
params=params)
if self.v2:
url = f'{url}/v2/synthesize'
params["utterance"] = sentence
else:
url = f'{url}/synthesize/{sentence}'
r = requests.get(url, params=params)
if r.ok:
return r.content
except:
Expand Down

0 comments on commit 4e3c24b

Please sign in to comment.