

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# SynthesizeSpeech
<a name="SynthesizeSpeechSamplePython"></a>

下列 Python 程式碼範例使用具有較短文字的 適用於 Python (Boto) 的 AWS SDK 合成語音，以進行近乎即時的處理。如需詳細資訊，請參閱 [SynthesizeSpeech](API_SynthesizeSpeech.md) 操作的參考。

此範例使用短字串的純文字。您可以使用 SSML 文字來進一步控制輸出。如需詳細資訊，請參閱[從 SSML 文件產生語音](ssml.md)。

```
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()
```