client = boto3.client("polly")
voices = ["Ivy", "Joanna", "Joey", "Justin",
"Kendra", "Kimberly", "Matthew", "Salli"]
response = client.synthesize_speech(
OutputFormat="mp3",
Text="Polly wants a cracker",
TextType="text",
VoiceId=random.choice(voices)
)
with open("out.mp3", "wb") as out:
with closing(response["AudioStream"]) as stream:
out.write(stream.read())