Created
January 20, 2017 19:01
-
-
Save kepstein/206740d919de64248b24e75a9466ae2a to your computer and use it in GitHub Desktop.
AWS Polly generates TTS and downloads the result to MP3 using Boto3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import boto3 | |
from contextlib import closing | |
client = boto3.client('polly') | |
response = client.synthesize_speech( | |
OutputFormat='mp3', | |
Text='Amazon Polly is a service that turns text into lifelike speech. Polly lets you create applications that talk, enabling you to build entirely new categories of speech-enabled products. Polly is an Amazon AI service that uses advanced deep learning technologies to synthesize speech that sounds like a human voice. Polly includes 47 lifelike voices spread across 24 languages, so you can select the ideal voice and build speech-enabled applications that work in many different countries.', | |
TextType='text', | |
VoiceId='Salli' | |
) | |
print response | |
if "AudioStream" in response: | |
with closing(response["AudioStream"]) as stream: | |
output = "polly-boto.mp3" | |
try: | |
# Open a file for writing the output as a binary stream | |
with open(output, "wb") as file: | |
file.write(stream.read()) | |
except IOError as error: | |
# Could not write to file, exit gracefully | |
print(error) | |
sys.exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment