Skip to content

Instantly share code, notes, and snippets.

@DaisukeMiyamoto
Created July 24, 2018 06:34
Show Gist options
  • Save DaisukeMiyamoto/80d292662530080038ade04f37b8e987 to your computer and use it in GitHub Desktop.
Save DaisukeMiyamoto/80d292662530080038ade04f37b8e987 to your computer and use it in GitHub Desktop.
polly example in japanese (日本語)
import boto3
from contextlib import closing
polly = boto3.client('polly')
text = '吾輩は猫である。名前はまだ無い。どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。この書生というのは時々我々を捕えて煮て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。'
voice = 'Mizuki'
filename = 'sample.mp3'
response = polly.synthesize_speech(
Text = text,
OutputFormat = 'mp3',
VoiceId = voice
)
print(response)
with closing(response['AudioStream']) as stream:
with open(filename, 'wb') as f:
f.write(stream.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment