Client

Amazon Polly bidirectional streaming over HTTP/2 with SigV4.

PollyStreamingClient

High-level client for Amazon Polly bidirectional streaming.

ServiceException

Base exception for all Polly bidirectional streaming service errors.

ServiceFailureException

An unknown condition has caused a Polly service failure.

ValidationException

The input provided to Polly is invalid.

ServiceQuotaExceededException

The Polly service quota has been exceeded for this account or operation.

ThrottlingException

The request to Polly was throttled by the service.

Detailed list

class amazon_polly_streaming.PollyStreamingClient(region='eu-central-1', pool_size=8)

Bases: object

High-level client for Amazon Polly bidirectional streaming.

Mirrors the TranscribeStreamingClient shape from amazon-transcribe-streaming-sdk-python: instantiate once for a given region, then call start_speech_synthesis_stream for each utterance.

Parameters:
  • region (str)

  • pool_size (int)

property region: str

The AWS region bound to this client.

async start_speech_synthesis_stream(*, text, voice_id, engine='generative', language_code='en-US', output_format='mp3', sample_rate='24000', use_pool=True)

Synthesize text via 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 one TextEvent and one CloseStreamEvent (each wrapped with a rolling chunk-signature) on the body channel. As Polly responds, decodes the inbound event stream and yields the bytes of every AudioEvent.

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 via pool_size on __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 AudioEvent received 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-type header.

  • RuntimeError – on transport failures (HTTP non-2xx, TLS / HTTP/2 negotiation, missing credentials).

Return type:

AsyncIterator[bytes]

exception amazon_polly_streaming.exceptions.ServiceException

Bases: Exception

Base exception for all Polly bidirectional streaming service errors.

exception amazon_polly_streaming.exceptions.ServiceFailureException

Bases: ServiceException

An unknown condition has caused a Polly service failure.

exception amazon_polly_streaming.exceptions.ValidationException

Bases: ServiceException

The input provided to Polly is invalid.

exception amazon_polly_streaming.exceptions.ServiceQuotaExceededException

Bases: ServiceException

The Polly service quota has been exceeded for this account or operation.

exception amazon_polly_streaming.exceptions.ThrottlingException

Bases: ServiceException

The request to Polly was throttled by the service.