Add TTS for AWS Polly

pull/432/head
Alvaro Martinez Llamojha 3 years ago
parent 9fd55ed111
commit 0788644765

@ -0,0 +1,31 @@
#!/usr/bin/env python3
from boto3 import Session
from botocore.exceptions import BotoCoreError, ClientError
import sys
max_chars = 0
def run(text, filepath):
session = Session(profile_name="polly")
polly = session.client("polly")
try:
# Request speech synthesis
response = polly.synthesize_speech(Text=text, OutputFormat="mp3",
VoiceId="Joanna", Engine = 'neural')
except (BotoCoreError, ClientError) as error:
# The service returned an error, exit gracefully
print(error)
sys.exit(-1)
# Access the audio stream from the response
if "AudioStream" in response:
file = open(filepath, 'wb')
file.write(response['AudioStream'].read())
file.close()
#print_substep(f"Saved Text {idx} to MP3 files successfully.", style="bold green")
else:
# The response didn't contain audio data, exit gracefully
print("Could not stream audio")
sys.exit(-1)

@ -3,10 +3,15 @@ import os
from utils.console import print_step, print_substep, print_table from utils.console import print_step, print_substep, print_table
from tts.engine_wrapper import TTSEngine from tts.engine_wrapper import TTSEngine
import tts.google_translate import tts.google_translate
import tts.aws_polly
## Add your provider here in the dictionary below ## Add your provider here in the dictionary below
TTSProviders = {"GoogleTranslate": tts.google_translate} TTSProviders = {
"GoogleTranslate": tts.google_translate,
"AWSPolly": tts.aws_polly
}
def save_text_to_mp3(reddit_obj): def save_text_to_mp3(reddit_obj):

Loading…
Cancel
Save