generate method synthesizes speech from text and returns the complete audio result.
Basic Usage
Voices and Languages
Specify the speaker voice and language:Generation Options
Customize sampling, chunking, and concurrency viaGenerationOptions:
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:- The
TextChunkertokenizes the input and splits it based on the strategy - Each chunk is generated independently (optionally in parallel)
- 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: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:<modelFolder>/embeddings/<voice>_<language>.promptcache.
Speech Result
TheSpeechResult contains the generated audio and detailed timing breakdown:
Timing Breakdown
TheSpeechTimings 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