首页 > 解决方案 > python boto3文本到语音'polly'

问题描述

我正在使用 python 3,当我尝试运行我的代码时,出现错误:

    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.

我的代码:

import boto3

client = boto3.client('polly')

output = client.synthesize_speech (
  Text = "Some random text I want to convert", OutputFormat = "mp3", VoiceId = 'Aditi'
)

print(output['AudioStream'])

file = open('speech.mp3', 'wb')
file.write(output['AudioStream'].read())
file.close()

标签: pythonboto3amazon-polly

解决方案


您需要尝试在客户端类中的某处添加区域名称。

IE

polly_client = boto3.Session(
                aws_access_key_id=,                     
    aws_secret_access_key=,
    region_name='us-west-2').client('polly')

这不一定是你想要的,但你明白了。该区域必须包含在某处


推荐阅读