Skip to main content
synthesizeStream yields audio in chunks so playback can start before the whole passage is rendered.

Basic usage

Method signature

The call is neither async nor throws: it returns immediately. Each element is a full RATTSOutput carrying one chunk of audio, not a bare Data. There is no onAudioChunk callback. The stream finishes without yielding anything when the SDK is not initialized or no model is loaded under .speechSynthesis.

Chunk shape

Every element is an RATTSOutput. The fields that matter while streaming:

Streaming audio player

RATTSOptions.defaults() sets audioFormat = .pcm and sampleRate = 22050. Prepare the player with the sampleRate reported on the first chunk rather than assuming a value.

SwiftUI integration

Sentence by sentence

When you want a real pause between sentences, synthesize each one and wait out its duration.
speak returns after playback finishes, so no manual sleep is needed.

Buffering

Scheduling every chunk the instant it arrives can stutter on slow devices. Hold a few back first.

Use cases

Accumulate tokens and hand each completed sentence to the synthesizer.
For a full conversational loop, the voice agent already wires VAD, STT, LLM, and TTS together.

Stopping

Cancelling the Task that consumes the stream also tears down the native session, because the stream’s termination handler cancels the underlying work.

Error handling

There is nothing to catch. Failures arrive as a chunk with a non-empty errorMessage.

Performance tips

Buffer a few chunks before starting playback so the player does not underrun.
Read sampleRate off the first chunk rather than hard-coding it. The default is 22050 Hz, but the engine can report something else.

synthesize()

Non-streaming synthesis

Voices

Voice selection