Call Polly from the AWS SDK for Python

update of boto3

Only version 1.4.1 or later of boto3 is compatible with Polly. Be sure to update before running.

$ pip install boto3 --upgrade

I get this error with older versions.

known_service_names=', '.join(sorted(known_services)))
botocore.exceptions.UnknownServiceError: Unknown service: 'polly'. Valid service names are: acm, apigateway, application-autoscaling, autoscaling, budgets, cloudformation, cloudfront, cloudhsm, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, codecommit, codedeploy, codepipeline, cognito-identity, cognito-idp, cognito-sync, config, datapipeline, devicefarm, directconnect, discovery, dms, ds, dynamodb, dynamodbstreams, ec2, ecr, ecs, efs, elasticache, elasticbeanstalk, elastictranscoder, elb, elbv2, emr, es, events, firehose, gamelift, glacier, iam, importexport, inspector, iot, iot-data, kinesis, kinesisanalytics, kms, lambda, logs, machinelearning, marketplacecommerceanalytics, meteringmarketplace, opsworks, rds, redshift, route53, route53domains, s3, sdb, servicecatalog, ses, sms, snowball, sns, sqs, ssm, storagegateway, sts, support, swf, waf, workspaces

Script to create mp3 file

Reference: https://boto3.readthedocs.io/en/latest/reference/services/polly.html#Polly.Client.synthesize_speech

import boto3

client = boto3.client(
    'polly'
)
response = client.synthesize_speech(
    OutputFormat='mp3',
    Text='Hello World',
    TextType='text',
    VoiceId='Joanna'
)
print response

Execution result

{u'ContentType': 'audio/mpeg', u'RequestCharacters': '11', 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '7030dcae-b76c-11e6-8bdd-03f34d26ede6', 'HTTPHeaders': {'x-amzn-requestid': '7030dcae-b76c-11e6-8bdd-03f34d26ede6', 'transfer-encoding': 'chunked', 'x-amzn-requestcharacters': '11', 'content-type': 'audio/mpeg', 'date': 'Thu, 01 Dec 2016 02:18:24 GMT'}}, u'AudioStream': <botocore.response.StreamingBody object at 0x102b69ad0>}

It seems that audio data is contained in ʻAudioStream`, so it seems good to take it out and process it. Or you may be able to make something like SaaS if you dig into S3 once and make it DL with presigned_url.

So far for the time being.

Recommended Posts

Call Polly from the AWS SDK for Python
boto3 (AWS SDK for Python) Note
Upgrade the Azure Machine Learning SDK for Python
Call Python library for text normalization from MATLAB
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Fleet provisioning with AWS IoT SDK for Python v2
[AWS] Operate SQS from SDK (send / receive) [Python] [Node.js]
Call your own python module from the ROS package
AWS SDK for Python (Boto3) development in Visual Studio 2017
Use AWS SDK for Python (boto) under Proxy environment
Call CPLEX from Python (DO cplex)
Call the API with python3.
Run AWS IoT Device SDK for Python on Raspberry Pi
Try a similar search for Image Search using the Python SDK [Search]
Create a Twitter BOT with the GoogleAppEngine SDK for Python
Call Matlab from Python to optimize
Call a Python function from p5.js.
Call C from Python with DragonFFI
Try the Python LINE Pay SDK
Call popcount from Ruby / Python / C #
Existence from the viewpoint of Python
Tips for calling Python from C
Use the Flickr API from Python
AWS Layer Creation Script for python
See python for the first time
Call python from nim with Nimpy
What is the python underscore (_) for?
Call C / C ++ from Python on Mac
Command for the current directory Python
Call c language from python (python.h)
How to change the log level of Azure SDK for Python
Let's touch Google's Vision API from Python for the time being
Load the remote Python SDK in IntelliJ
Introducing the BOT framework Minette for Python
"Python AI programming" starting from 0 for windows
Learning notes from the beginning of Python 1
Python Master RTA for the time being
Launch the Discord Python bot for 24 hours.
Working with OpenStack using the Python SDK
[Cloudian # 1] Try to access object storage with AWS SDK for Python (boto3)
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
MongoDB for the first time in Python
Call the python debugger at any time
Launch the Python interpreter from Git bash
Python> Output numbers from 1 to 100, 501 to 600> For csv
From Python 3.4, pip becomes the standard installer! ??
Search for synonyms from the word list (csv) using Python Japanese WordNet
Call a command from Python (Windows version)
Learning notes from the beginning of Python 2
[Python] Get the main color from the screenshot
Prepare the development environment for Python on AWS Cloud9 (pip install & time change)
I made a Docker image that can call FBX SDK Python from Node.js
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Get the contents of git diff from python
The fastest way for beginners to master Python
[Python] I tried substituting the function name for the function name
The story of low learning costs for Python
Created a Python wrapper for the Qiita API
[Python] matplotlib: Format the diagram for your dissertation
I searched for railway senryu from the data
Wagtail is the best CMS for Python! (Perhaps)