MediaPipeTasksAudio Framework Reference

TextToSpeech

final class TextToSpeech: Sendable

MediaPipe TextToSpeech task interface for Swift (iOS / macOS).

  • Internal sentinel path used for fast, hermetic unit testing without a .litertlm file.

    Declaration

    Swift

    static let syntheticTestModelPath: String
  • Declaration

    Swift

    init(options: TextToSpeechOptions) throws
  • Thread-safe, lock-free barge-in cancellation. Immediately aborts any in-flight synthesize or synthesizeStream call on another thread.

    Declaration

    Swift

    final func cancel()
  • Queries available voices for this initialized TextToSpeech instance and its loaded .litertlm bundle.

    Declaration

    Swift

    final func listVoices() throws -> [VoiceInfo]
  • Opens a TTSStream for 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 text on the calling thread and returns the AudioResult. 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's cancel().

    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 the for try await loop or cancelling the calling Task immediately triggers MpTextToSpeechStreamCancel + MpTextToSpeechStreamClose.

    Declaration

    Swift

    final func synthesizeStream(_ text: String, options: SynthesisOptions? = nil) -> AsyncThrowingStream<AudioChunk, any Error>