# TextToSpeech

    final class TextToSpeech: Sendable

MediaPipe TextToSpeech task interface for Swift (iOS / macOS).
- `
  ### [syntheticTestModelPath](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC22syntheticTestModelPathSSvpZ)

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

  #### Declaration

  Swift

      static let syntheticTestModelPath: String

- `
  ### [init(options:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC7optionsAcA0efG7OptionsV_tKcfc)

  ` Creates a new `TextToSpeech` instance.

  #### Declaration

  Swift

      init(options: TextToSpeechOptions) throws

- `
  ### [cancel()](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC6cancelyyF)

  ` Thread-safe, lock-free barge-in cancellation. Immediately aborts any in-flight `synthesize` or `synthesizeStream` call on another thread.

  #### Declaration

  Swift

      final func cancel()

- `
  ### [listVoices()](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC10listVoicesSayAA9VoiceInfoVGyKF)

  ` Queries available voices for this initialized `TextToSpeech` instance and its loaded `.litertlm` bundle.

  #### Declaration

  Swift

      final func listVoices() throws -> [VoiceInfo]

- `
  ### [openStream(_:options:finishInput:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC10openStream_7options11finishInputAA9TTSStreamCSS_AA16SynthesisOptionsVSgSbtKF)

  ` 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

- `
  ### [synthesize(_:options:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC10synthesize_7optionsAA0D6ResultVSS_AA16SynthesisOptionsVSgtKF)

  ` 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

- `
  ### [synthesizeAsync(_:options:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC15synthesizeAsync_7optionsAA0D6ResultVSS_AA16SynthesisOptionsVSgtYaKF)

  ` 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

- `
  ### [synthesizeStream(_:options:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/TextToSpeech.md.txt#/s:19MediaPipeTasksAudio12TextToSpeechC16synthesizeStream_7optionsScsyAA0D5ChunkVs5Error_pGSS_AA16SynthesisOptionsVSgtF)

  ` Streams synthesized PCM `AudioChunk`s 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>