Help us understand the problem. What is going on with this article?

AWS Text to Speech

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)

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away