Created
November 9, 2018 13:13
-
-
Save greg76/c6458bfe897a6ae3cbbdbb9e3e619743 to your computer and use it in GitHub Desktop.
simple example on how to "text-to-speech" with amazon's polly service
This file contains hidden or 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/env python3 | |
from boto3 import client | |
from contextlib import closing | |
polly = client("polly", 'us-east-1') | |
voice = 'Brian' | |
response = polly.synthesize_speech( | |
Text='''Imagine how your bullet points turn into presenter notes! | |
And your visuals start to speak for themselves.''', | |
OutputFormat="mp3", | |
VoiceId=voice) | |
print(response) | |
if "AudioStream" in response: | |
with closing(response["AudioStream"]) as stream: | |
data = stream.read() | |
filename = voice + '.mp3' | |
fo = open(filename, "bw+") | |
fo.write(data) | |
fo.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment