AWS喋らせよう!(備忘録 貧乏録)
# !/usr/local/bin/python3.6
# AWS
from boto3 import Session
from botocore.exceptions import BotoCoreError, ClientError
from contextlib import closing
import os,sys,subprocess
session = Session(region_name="us-west-2")
polly = session.client("polly")
ttsdt=[
('Ivy' ,"Thank you for calling. I'm sorry but I can't answer your call right now. Please leave a message at the tone . I'll get back to you as soon as possible."),
('Joey' ,"Thank you for calling. I'm sorry but I can't answer your call right now. Please leave a message at the tone . I'll get back to you as soon as possible."),
('Mizuki',"お電話ありがとうございます。ただいま、電話に出ることができません。ピーッという音が鳴りましたら[発信音の後に]、メッセージをお願いします。こちらからすぐにお電話いたします。"),
('Takumi',"お電話ありがとうございます。ただいま、電話に出ることができません。ピーッという音が鳴りましたら[発信音の後に]、メッセージをお願いします。こちらからすぐにお電話いたします。")
]
for id,tx in ttsdt:
print(tx)
try:
response = polly.synthesize_speech(Text=tx, OutputFormat="mp3", VoiceId=id)
except (BotoCoreError, ClientError) as error:
print(error)
sys.exit(-1)
if "AudioStream" in response:
with closing(response["AudioStream"]) as stream:
output = id+".mp3"
try:
with open(output, "wb") as file:
file.write(stream.read())
except IOError as error:
print(error)
sys.exit(-1)
print("synthesize_speech OK ->>" + output)
subprocess.Popen(['mpg123', '-q',output ]).wait()
else:
print("Could not stream audio")
sys.exit(-1)
AWSサンプル TTS pic.twitter.com/OTwYQ9mY5D
— utaca.rich (@RichUtaka) May 11, 2019