Skip to content

Instantly share code, notes, and snippets.

@greg76
Created November 9, 2018 13:13
Show Gist options
  • Save greg76/c6458bfe897a6ae3cbbdbb9e3e619743 to your computer and use it in GitHub Desktop.
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
#!/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