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
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
{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