TextToSpeech
final class TextToSpeech: SendableMediaPipe TextToSpeech task interface for Swift (iOS / macOS).
-
Internal sentinel path used for fast, hermetic unit testing without a
.litertlmfile.Declaration
Swift
static let syntheticTestModelPath: String -
Declaration
Swift
init(options: TextToSpeechOptions) throws -
Thread-safe, lock-free barge-in cancellation. Immediately aborts any in-flight
synthesizeorsynthesizeStreamcall on another thread.Declaration
Swift
final func cancel() -
Queries available voices for this initialized
TextToSpeechinstance and its loaded.litertlmbundle.Declaration
Swift
final func listVoices() throws -> [VoiceInfo] -
Opens a
TTSStreamfor Level 2 incremental LLM text streaming (pushText+finishInput) or synchronous pull iteration (readNext).Declaration
Swift
final func openStream(_ initialText: String = "", options: SynthesisOptions? = nil, finishInput: Bool = false) throws -> TTSStream -
Synchronously synthesizes
texton the calling thread and returns theAudioResult. Multi-sentence inputs are automatically split at sentence boundaries internally.Declaration
Swift
final func synthesize(_ text: String, options: SynthesisOptions? = nil) throws -> AudioResult -
Non-blocking async convenience wrapper that runs synthesis off the main thread and automatically wires Swift structured concurrency
Task.cancel()to the specific stream'scancel().Declaration
Swift
final func synthesizeAsync(_ text: String, options: SynthesisOptions? = nil) async throws -> AudioResult -
Streams synthesized PCM
AudioChunks as each sentence or vocoder slice completes. Breaking out of thefor try awaitloop or cancelling the callingTaskimmediately triggersMpTextToSpeechStreamCancel+MpTextToSpeechStreamClose.Declaration
Swift
final func synthesizeStream(_ text: String, options: SynthesisOptions? = nil) -> AsyncThrowingStream<AudioChunk, any Error>