Skip to main content

Usage guide

Setup, environment variables, and Python/JavaScript/Go usage examples.

AzureTTS

Azure Cognitive Services Neural Text-to-Speech provider. Synthesizes speech using Azure Neural TTS voices, supporting hundreds of voices across 60+ languages at up to 48 kHz. Standard Neural voices are available at 24 kHz and 48 kHz; streaming output is returned as PCM audio.

Constructor

speech_key
Optional[str]
Azure Speech resource subscription key. Falls back to the AZURE_SPEECH_KEY environment variable when omitted.
speech_region
Optional[str]
Azure region identifier for the Speech resource (e.g. "eastus", "westeurope", "southeastasia"). Falls back to the AZURE_REGION environment variable, then "eastus" as a hard default. Must match the region where your Azure Speech resource was created. Keys are region-scoped.
voice
str
default:"en-US-JennyNeural"
Azure Neural TTS voice name in "<locale>-<Name>Neural" format. Defaults to "en-US-JennyNeural" (female, US English). Common options include "en-US-AriaNeural", "en-US-GuyNeural", "en-GB-SoniaNeural", "fr-FR-DeniseNeural", "de-DE-KatjaNeural", "ja-JP-NanamiNeural". See the Azure language-support docs for the full voice catalog.
sample_rate
int
default:"24000"
PCM output sample rate in Hz. Azure Neural TTS natively supports 24000 (standard) and 48000 (high-fidelity). Defaults to 24000.

aclose

Release any resources held by the provider.

emit

Emit an event, invoking all registered handlers with the given arguments. Handlers are called in registration order. Coroutine handlers are scheduled on the running event loop. If the emitter is closed, the call is a no-op.
event
T
required
The event to emit.

interrupt

Interrupt and cancel the current synthesis for the active session, if any.

off

Remove a previously registered handler for an event. If the handler is not registered for the event, the call is a no-op.
event
T
required
The event the handler was registered for.
callback
Callable[..., Any]
required
The handler to remove.

on

Register a handler for an event. Can be used directly by passing a callback, or as a decorator when callback is omitted.
event
T
required
The event to listen for.
callback
Callable[..., Any] | None
The handler to invoke when the event is emitted. If None, a decorator is returned that registers the decorated function.
returns
Callable[..., Any]
The registered callback when callback is provided, otherwise a decorator that registers and returns the function it wraps.

on_first_audio_byte

Register the callback invoked when the first audio byte is produced.
callback
'Callable[[int, int], Awaitable[None] | None]'
required
A callable, optionally async, invoked with synthesis timing information when the first audio byte is emitted.

synthesize

Synthesize the given text into speech. Implementations should convert the text to audio. The default behavior forwards the text to the active session for playback when one is present.
text
Any
required
The text to synthesize; coerced to a string if needed.