Client
Amazon Polly bidirectional streaming over HTTP/2 with SigV4.
High-level client for Amazon Polly bidirectional streaming. |
|
|
Base exception for all Polly bidirectional streaming service errors. |
|
An unknown condition has caused a Polly service failure. |
|
The input provided to Polly is invalid. |
|
The Polly service quota has been exceeded for this account or operation. |
|
The request to Polly was throttled by the service. |
Detailed list
- class amazon_polly_streaming.PollyStreamingClient(region='eu-central-1', pool_size=8)
Bases:
objectHigh-level client for Amazon Polly bidirectional streaming.
Mirrors the
TranscribeStreamingClientshape fromamazon-transcribe-streaming-sdk-python: instantiate once for a given region, then callstart_speech_synthesis_streamfor each utterance.- async start_speech_synthesis_stream(*, text, voice_id, engine='generative', language_code='en-US', output_format='mp3', sample_rate='24000', use_pool=True)
Synthesize
textvia Polly bidirectional streaming and yield audio chunks.Opens an HTTP/2 connection to
polly.<region>.amazonaws.com, signs the initial request with SigV4, then writes oneTextEventand oneCloseStreamEvent(each wrapped with a rolling chunk-signature) on the body channel. As Polly responds, decodes the inbound event stream and yields the bytes of everyAudioEvent.- Parameters:
text (str) – The text to synthesize.
voice_id (str) – Polly voice id (must be a generative voice supporting bidirectional streaming, e.g.
"Matthew").engine (str) – Polly engine name. Currently only
"generative"is supported by the bidirectional streaming API.language_code (str) – BCP-47 language code (only used for bilingual voices).
output_format (str) – Audio format (
"mp3","pcm","ogg_vorbis", …). Default"mp3".sample_rate (str) – Sample rate in Hz, as a string. Default
"24000".use_pool (bool) – If
True(default), reuse a cached HTTP/2 connection from this client’s connection pool (configured viapool_sizeon__init__), avoiding TLS handshake and HTTP/2 settings exchange between calls to the same Polly endpoint. Disable for one-shot scripts where the cache adds complexity without benefit.
- Yields:
Bytes of audio for each
AudioEventreceived from Polly, in order.- Raises:
ServiceException – base class for any service-side error. Subclasses (
ServiceFailureException,ValidationException,ServiceQuotaExceededException,ThrottlingException) are raised when Polly returns a framed exception with a recognised:exception-typeheader.RuntimeError – on transport failures (HTTP non-2xx, TLS / HTTP/2 negotiation, missing credentials).
- Return type:
AsyncIterator[bytes]
- exception amazon_polly_streaming.exceptions.ServiceException
Bases:
ExceptionBase exception for all Polly bidirectional streaming service errors.
- exception amazon_polly_streaming.exceptions.ServiceFailureException
Bases:
ServiceExceptionAn unknown condition has caused a Polly service failure.
- exception amazon_polly_streaming.exceptions.ValidationException
Bases:
ServiceExceptionThe input provided to Polly is invalid.
- exception amazon_polly_streaming.exceptions.ServiceQuotaExceededException
Bases:
ServiceExceptionThe Polly service quota has been exceeded for this account or operation.
- exception amazon_polly_streaming.exceptions.ThrottlingException
Bases:
ServiceExceptionThe request to Polly was throttled by the service.