View a markdown version of this page

SynthesizeSpeech - Amazon Polly
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

SynthesizeSpeech

以下 Python 代码示例使用适用于 Python (Boto) 的 Amazon SDK 将语音与较短的文本合成以进行近实时处理。有关更多信息,请参阅参考中的 SynthesizeSpeech 操作。

此示例使用一小串纯文本。您可以使用 SSML 文本来更好地控制输出。有关更多信息,请参阅 由 SSML 文档生成语音

import boto3 polly_client = boto3.Session( aws_access_key_id=, aws_secret_access_key=, region_name='us-west-2').client('polly') response = polly_client.synthesize_speech(VoiceId='Joanna', OutputFormat='mp3', Text = 'This is a sample text to be synthesized.', Engine = 'neural') file = open('speech.mp3', 'wb') file.write(response['AudioStream'].read()) file.close()