MediaPipeTasksAudio Framework Reference

TextToSpeech

final class TextToSpeech : @unchecked Sendable

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

  • Creates and initializes a TextToSpeech instance configured with TextToSpeechOptions.

    Declaration

    Swift

    public init(options: TextToSpeechOptions) throws
  • Queries available voices for this initialized TextToSpeech instance.

    Declaration

    Swift

    public func listVoices() throws -> [TtsVoiceInfo]
  • Synchronously synthesizes text and returns the TtsAudioResult.

    Declaration

    Swift

    public func synthesize(_ text: String, options: TtsSynthesisOptions? = nil) throws -> TtsAudioResult
  • Asynchronously synthesizes text off the main thread with structured concurrency cancellation.

    Declaration

    Swift

    public func synthesizeAsync(_ text: String, options: TtsSynthesisOptions? = nil) async throws -> TtsAudioResult
  • Streams synthesized PCM TtsAudioChunk values as each sentence completes.

    Declaration

    Swift

    public func synthesizeStream(_ text: String, options: TtsSynthesisOptions? = nil) -> AsyncThrowingStream
  • Opens a TtsStream for incremental LLM text streaming (pushText + finishInput) or pull iteration (readNext).

    Declaration

    Swift

    public func openStream(_ initialText: String = "", options: TtsSynthesisOptions? = nil, finishInput: Bool = false) throws -> TtsStream
  • Thread-safe, lock-free barge-in cancellation of any in-flight synthesis.

    Declaration

    Swift

    public func cancel()