Skip to main content
The generate method synthesizes speech from text and returns the complete audio result.

Basic Usage

Voices and Languages

Specify the speaker voice and language:
See Voices & Languages for the complete list of available voices and languages.

Generation Options

Customize sampling, chunking, and concurrency via GenerationOptions:

Sampling Parameters

Float
default:"0.9"
Sampling temperature. Higher values (e.g., 1.0) increase randomness; lower values (e.g., 0.5) make output more deterministic.
Int
default:"50"
Top-k sampling: only sample from the k most likely tokens at each step.
Float
default:"1.05"
Penalty for repeated tokens. Values > 1.0 discourage repetition.
Int
default:"245"
Maximum number of tokens to generate per chunk.

Chunking Strategy

Long text is automatically split into chunks for efficient generation:
How it works:
  1. The TextChunker tokenizes the input and splits it based on the strategy
  2. Each chunk is generated independently (optionally in parallel)
  3. Audio chunks are assembled with crossfade at boundaries
Sentence-based chunking preserves natural prosody boundaries. Token-based chunking may split mid-sentence for very long passages.

Concurrent Generation

Control how many chunks generate in parallel:
Higher concurrency increases memory usage (each worker holds its own KV cache). For memory-constrained devices, use concurrentWorkerCount = 1.

Style Instructions (1.7B Only)

The 1.7B model accepts natural-language style instructions to control prosody:
Style instructions are only supported by the 1.7B model. The 0.6B model ignores this parameter.

Progress Callbacks

Receive per-step audio during generation:
[Float]
PCM audio samples generated in this step.
SpeechTimings
Cumulative timing breakdown for the current generation.
TimeInterval?
Wall-clock time for the first decoding step (only set on first callback).
Int?
Index of the current chunk (when using chunked generation).
Int?
Total number of chunks (when using chunked generation).
Int
Number of decoding steps completed so far.
Int?
Estimated total decoding steps.

Prompt Caching

TTSKit automatically caches the invariant prefix embeddings for each voice/language combination:

Manual Cache Management

You can also build and save prompt caches explicitly:
Caches are saved to <modelFolder>/embeddings/<voice>_<language>.promptcache.

Speech Result

The SpeechResult contains the generated audio and detailed timing breakdown:

Timing Breakdown

The SpeechTimings struct provides detailed performance metrics:

Saving Audio

Generated audio can be saved to WAV or M4A:
M4A export is not available on watchOS and automatically falls back to WAV.

Next Steps

Playback

Stream audio with real-time playback

Voices & Languages

Explore available voices and languages