From d03f05a1e4ab5f0c9bfb58655c58145e58c0b24b Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 1 Jul 2022 19:09:41 -0400 Subject: [PATCH] feat: improved err handling in streamlabs_polly.py --- TTS/streamlabs_polly.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index 4e2f56f..68ec379 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -47,7 +47,11 @@ class StreamlabsPolly: 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) +#StreamlabsPolly().run(text=str('hi hi ' * 92)[1:], filepath='hello.mp3', random_voice=True)