

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

# StartSpeechSynthesisStream
<a name="API_StartSpeechSynthesisStream"></a>

通过双向流媒体连接合成 UTF-8 输入、纯文本或 SSML。在 HTTP/2 标头中指定合成参数，将文本作为输入流上的事件递增发送，并在合成音频可用时接收合成的音频。

此操作可作为双向`SynthesizeSpeech`对应物：
+  [SynthesizeSpeech](https://docs.amazonaws.cn/polly/latest/dg/API_SynthesizeSpeech.html) 

## 请求语法
<a name="API_StartSpeechSynthesisStream_RequestSyntax"></a>

```
POST /v1/synthesisStream HTTP/1.1
x-amzn-Engine: Engine
x-amzn-LanguageCode: LanguageCode
x-amzn-LexiconNames: LexiconNames
x-amzn-OutputFormat: OutputFormat
x-amzn-SampleRate: SampleRate
x-amzn-VoiceId: VoiceId
Content-type: application/json

{
   "CloseStreamEvent": { 
   },
   "TextEvent": { 
      "FlushStreamConfiguration": { 
         "Force": boolean
      },
      "Text": "string",
      "TextType": "string"
   }
}
```

## URI 请求参数
<a name="API_StartSpeechSynthesisStream_RequestParameters"></a>

请求使用以下 URI 参数。

 ** [Engine](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-Engine"></a>
指定 Amazon Polly 在处理语音合成输入文本时使用的引擎。当前，仅支持该`generative`引擎。如果您指定了所选引擎不支持的声音，Amazon Polly 将返回错误。  
有效值：`standard | neural | long-form | generative`  
是否必需：是

 ** [LanguageCode](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-LanguageCode"></a>
一个可选参数，用于设置语音合成请求的语言代码。只有在使用双语语音时才指定此参数。如果使用双语语音但未指定语言代码，则 Amazon Polly 将使用双语语音的默认语言。  
有效值：`arb | cmn-CN | cy-GB | da-DK | de-DE | en-AU | en-GB | en-GB-WLS | en-IN | en-US | es-ES | es-MX | es-US | fr-CA | fr-FR | is-IS | it-IT | ja-JP | hi-IN | ko-KR | nb-NO | nl-NL | pl-PL | pt-BR | pt-PT | ro-RO | ru-RU | sv-SE | tr-TR | en-NZ | en-ZA | ca-ES | de-AT | yue-CN | ar-AE | fi-FI | en-IE | nl-BE | fr-BE | cs-CZ | de-CH | en-SG`

 ** [LexiconNames](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-LexiconNames"></a>
服务在合成过程中要应用的一个或多个发音词典的名称。只有当词典语言与语音语言匹配时，Amazon Polly 才会应用词典。  
数组成员：最多 5 项。  
模式：`[0-9A-Za-z]{1,20}`

 ** [OutputFormat](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-OutputFormat"></a>
合成语音的音频格式。目前，Amazon Polly 不支持 JSON 语音标记。  
有效值：`json | mp3 | ogg_opus | ogg_vorbis | pcm`  
是否必需：是

 ** [SampleRate](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-SampleRate"></a>
音频频率，以 Hz 为单位指定。

 ** [VoiceId](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-VoiceId"></a>
合成中要使用的声音。要获取可用语音列表 IDs，请使用[DescribeVoices](https://docs.amazonaws.cn/polly/latest/dg/API_DescribeVoices.html)操作。  
有效值：`Aditi | Amy | Astrid | Bianca | Brian | Camila | Carla | Carmen | Celine | Chantal | Conchita | Cristiano | Dora | Emma | Enrique | Ewa | Filiz | Gabrielle | Geraint | Giorgio | Gwyneth | Hans | Ines | Ivy | Jacek | Jan | Joanna | Joey | Justin | Karl | Kendra | Kevin | Kimberly | Lea | Liv | Lotte | Lucia | Lupe | Mads | Maja | Marlene | Mathieu | Matthew | Maxim | Mia | Miguel | Mizuki | Naja | Nicole | Olivia | Penelope | Raveena | Ricardo | Ruben | Russell | Salli | Seoyeon | Takumi | Tatyana | Vicki | Vitoria | Zeina | Zhiyu | Aria | Ayanda | Arlet | Hannah | Arthur | Daniel | Liam | Pedro | Kajal | Hiujin | Laura | Elin | Ida | Suvi | Ola | Hala | Andres | Sergio | Remi | Adriano | Thiago | Ruth | Stephen | Kazuha | Tomoko | Niamh | Sofie | Lisa | Isabelle | Zayd | Danielle | Gregory | Burcu | Jitka | Sabrina | Jasmine | Jihye | Ambre | Beatrice | Florian | Lennart | Lorenzo | Tiffany`  
是否必需：是

## 请求体
<a name="API_StartSpeechSynthesisStream_RequestBody"></a>

请求接受采用 JSON 格式的以下数据。

 ** [CloseStreamEvent](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-CloseStreamEvent"></a>
一个表示输入流结束的事件。  
类型：[CloseStreamEvent](API_CloseStreamEvent.md) 对象  
必需：否

 ** [TextEvent](#API_StartSpeechSynthesisStream_RequestSyntax) **   <a name="polly-StartSpeechSynthesisStream-request-TextEvent"></a>
包含待合成内容的文本事件。  
类型：[TextEvent](API_TextEvent.md) 对象  
必需：否

## 响应语法
<a name="API_StartSpeechSynthesisStream_ResponseSyntax"></a>

```
HTTP/1.1 200
Content-type: application/json

{
   "AudioEvent": { 
      "AudioChunk": blob
   },
   "ServiceFailureException": { 
   },
   "ServiceQuotaExceededException": { 
   },
   "StreamClosedEvent": { 
      "RequestCharacters": number
   },
   "ThrottlingException": { 
   },
   "ValidationException": { 
   }
}
```

## 响应元素
<a name="API_StartSpeechSynthesisStream_ResponseElements"></a>

如果此操作成功，则该服务将会发送回 HTTP 200 响应。

服务以 JSON 格式返回以下数据。

 ** [AudioEvent](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-AudioEvent"></a>
包含合成语音的音频事件。  
类型：[AudioEvent](API_AudioEvent.md) 对象

 ** [ServiceFailureException](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-ServiceFailureException"></a>
未知情况导致服务故障。  
类型：异常  
HTTP 状态代码：500

 ** [ServiceQuotaExceededException](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-ServiceQuotaExceededException"></a>
表示将超过服务配额的异常。  
类型：异常  
HTTP 状态代码：402

 ** [StreamClosedEvent](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-StreamClosedEvent"></a>
带有摘要信息的事件，表示直播已关闭。  
类型：[StreamClosedEvent](API_StreamClosedEvent.md) 对象

 ** [ThrottlingException](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-ThrottlingException"></a>
表示请求已被限制的异常。  
类型：异常  
HTTP 状态代码：400

 ** [ValidationException](#API_StartSpeechSynthesisStream_ResponseSyntax) **   <a name="polly-StartSpeechSynthesisStream-response-ValidationException"></a>
表示输入未通过验证的异常。  
类型：异常  
HTTP 状态代码：400

## 错误
<a name="API_StartSpeechSynthesisStream_Errors"></a>

 ** ServiceFailureException **   
未知情况导致服务故障。  
HTTP 状态代码：500

 ** ServiceQuotaExceededException **   
该请求会导致超出服务限额。    
 ** quotaCode **   
标识特定配额的配额代码。  
 ** serviceCode **   
标识源服务的服务代码。
HTTP 状态代码：402

 ** ThrottlingException **   
由于请求限制，该请求被拒绝。    
 ** throttlingReasons **   
解释请求被限制的原因列表。
HTTP 状态代码：400

 ** ValidationException **   
输入未能满足 服务指定的约束。    
 ** fields **   
导致验证错误的字段。  
 ** reason **   
请求验证失败的原因。
HTTP 状态代码：400

## 另请参阅
<a name="API_StartSpeechSynthesisStream_SeeAlso"></a>

有关以特定语言之一使用此 API 的更多信息 Amazon SDKs，请参阅以下内容：
+  [Amazon 命令行界面 V2](https://docs.amazonaws.cn/goto/cli2/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于.NET 的 SDK V4](https://docs.amazonaws.cn/goto/DotNetSDKV4/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 C\$1\$1 的 SDK](https://docs.amazonaws.cn/goto/SdkForCpp/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 Go v2 的 SDK](https://docs.amazonaws.cn/goto/SdkForGoV2/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 Java 的 SDK V2](https://docs.amazonaws.cn/goto/SdkForJavaV2/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon JavaScript V3 版软件开发工具包](https://docs.amazonaws.cn/goto/SdkForJavaScriptV3/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 Kotlin 的 SDK](https://docs.amazonaws.cn/goto/SdkForKotlin/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 PHP 的 SDK V3](https://docs.amazonaws.cn/goto/SdkForPHPV3/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon Python 软件开发工具包](https://docs.amazonaws.cn/goto/boto3/polly-2016-06-10/StartSpeechSynthesisStream) 
+  [Amazon 适用于 Ruby V3 的 SDK](https://docs.amazonaws.cn/goto/SdkForRubyV3/polly-2016-06-10/StartSpeechSynthesisStream) 