StartSpeechSynthesisStream
Synthesizes UTF-8 input, plain text, or SSML over a bidirectional streaming connection. Specify synthesis parameters in HTTP/2 headers, send text incrementally as events on the input stream, and receive synthesized audio as it becomes available.
This operation serves as a bidirectional counterpart to SynthesizeSpeech:
To use a custom voice, specify its ID in VoiceId. The
voice must be in active status. If the voice is in
pending or failed status, the request fails with
ConflictException. If no custom voice with the specified ID
exists in your account and Region, the request fails with
ResourceNotFoundException. If the custom voice uses a
customer managed key, you need kms:Decrypt permission on the
key. If you disabled the key or scheduled it for deletion, the request
fails with ValidationException. If you don't have permission
to use the key, the request fails with
AccessDeniedException. If AWS KMS throttles Amazon Polly's
request to use the key, the request fails with
ThrottlingException.
Request Syntax
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 Request Parameters
The request uses the following URI parameters.
- Engine
-
Specifies the engine for Amazon Polly to use when processing input text for speech synthesis. Currently, only the
generativeengine is supported. If you specify a voice that the selected engine doesn't support, Amazon Polly returns an error.Valid Values:
standard | neural | long-form | generativeRequired: Yes
- LanguageCode
-
An optional parameter that sets the language code for the speech synthesis request. Specify this parameter only when using a bilingual voice. If a bilingual voice is used and no language code is specified, Amazon Polly uses the default language of the bilingual voice.
Valid Values:
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
-
The names of one or more pronunciation lexicons for the service to apply during synthesis. Amazon Polly applies lexicons only when the lexicon language matches the voice language.
Array Members: Maximum number of 5 items.
Pattern:
[0-9A-Za-z]{1,20} - OutputFormat
-
The audio format for the synthesized speech. Currently, Amazon Polly does not support JSON speech marks.
Valid Values:
json | mp3 | ogg_opus | ogg_vorbis | pcm | mulaw | alawRequired: Yes
- SampleRate
-
The audio frequency, specified in Hz.
- VoiceId
-
The voice ID to use for the synthesis. To get a list of available voice IDs, use the DescribeVoices operation. To use a custom voice, specify the voice ID that
CreateVoicereturned, for example,vc-9a8fa85dd3. You can't specify the ARN of a voice.Valid Values:
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 | Arjun | Carlos | Carolina | Curtis | Hyunduk | Kenneth | Kiara | Leo | Nate | TinaRequired: Yes
Request Body
The request accepts the following data in JSON format.
- CloseStreamEvent
-
An event indicating the end of the input stream.
Type: CloseStreamEvent object
Required: No
- TextEvent
-
A text event containing content to be synthesized.
Type: TextEvent object
Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"AudioEvent": {
"AudioChunk": blob
},
"ServiceFailureException": {
},
"ServiceQuotaExceededException": {
},
"StreamClosedEvent": {
"RequestCharacters": number
},
"ThrottlingException": {
},
"ValidationException": {
}
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- AudioEvent
-
An audio event containing synthesized speech.
Type: AudioEvent object
- ServiceFailureException
-
An unknown condition has caused a service failure.
Type: Exception
HTTP Status Code: 500
- ServiceQuotaExceededException
-
An exception indicating a service quota would be exceeded.
Type: Exception
HTTP Status Code: 402
- StreamClosedEvent
-
An event, with summary information, indicating the stream has closed.
Type: StreamClosedEvent object
- ThrottlingException
-
An exception indicating the request was throttled.
Type: Exception
HTTP Status Code: 400
- ValidationException
-
An exception indicating the input failed validation.
Type: Exception
HTTP Status Code: 400
Errors
For information about the errors that are common to all actions, see Common Error Types.
- ConflictException
-
The request conflicts with the current state of the resource. For a custom voice, the voice isn't in the status that the operation requires. Check the status with
GetVoice, and then try again.- resourceId
-
The ID of the resource that the request conflicts with.
- resourceType
-
The type of the resource that the request conflicts with.
HTTP Status Code: 409
- ResourceNotFoundException
-
Amazon Polly can't find the specified resource. Verify that the resource exists in the AWS account and Region of the request and that its ARN or ID is spelled correctly, and then try again.
- resourceId
-
The identifier of the resource that wasn't found.
- resourceType
-
The type of the resource that wasn't found.
HTTP Status Code: 404
- ServiceFailureException
-
An unknown condition has caused a service failure.
HTTP Status Code: 500
- ServiceQuotaExceededException
-
The request would cause a service quota to be exceeded.
- quotaCode
-
The quota code identifying the specific quota.
- serviceCode
-
The service code identifying the originating service.
HTTP Status Code: 402
- ThrottlingException
-
The request was denied because of request throttling.
- throttlingReasons
-
A list of reasons explaining why the request was throttled.
HTTP Status Code: 400
- ValidationException
-
The input fails to satisfy the constraints specified by the service.
- fields
-
The fields that caused the validation error.
- reason
-
The reason the request failed validation. If Amazon Polly can't use the AWS KMS key that you specified in
CreateVoice,fieldsnamesCustomerManagedEncryption.KmsKeyArnand the reason is one of the following:- kmsKeyNotFound
-
No key with the specified ARN exists.
- kmsKeyUnusable
-
The key is disabled, scheduled for deletion, or missing its key material, or it isn't a symmetric encryption key.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: