Improved AWS Polly eh

improved handling for errors like
like #929
pull/880/head
Jason 3 years ago
parent 1872ef36c1
commit a7c54f48e8

@ -1,6 +1,6 @@
#!/usr/bin/env python3
from boto3 import Session
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError, ClientError, ProfileNotFound
import sys
from utils import settings
import random
@ -30,6 +30,7 @@ class AWSPolly:
self.voices = voices
def run(self, text, filepath, random_voice: bool = False):
try:
session = Session(profile_name="polly")
polly = session.client("polly")
if random_voice:
@ -61,6 +62,13 @@ class AWSPolly:
# The response didn't contain audio data, exit gracefully
print("Could not stream audio")
sys.exit(-1)
except ProfileNotFound:
print("You need to install the AWS CLI and configure your profile")
print("""
Linux: https://docs.aws.amazon.com/polly/latest/dg/setup-aws-cli.html
Windows: https://docs.aws.amazon.com/polly/latest/dg/install-voice-plugin2.html
""")
sys.exit(-1)
def randomvoice(self):
return random.choice(self.voices)

Loading…
Cancel
Save