> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# synthesize()

> Turn text into audio

Three methods, depending on whether you want the samples or just want it spoken.

```swift theme={"theme":"css-variables"}
import RunAnywhereONNX
ONNX.register()

// Get the audio back
let audio = try await RunAnywhere.tts.synthesize("Hello from RunAnywhere")

// Play it through the device
let handle = try await RunAnywhere.tts.speak("Hello from RunAnywhere")
await handle.waitForPlayout()
```

## Signatures

```swift theme={"theme":"css-variables"}
func synthesize(_ text: String, options: TtsOptions? = nil) async throws -> Audio
func synthesizeStream(_ text: String, options: TtsOptions? = nil) async throws
    -> AsyncThrowingStream<AudioChunk, Error>
func speak(_ text: String, options: TtsOptions? = nil) async throws -> SpeechHandle
func stop() async
func voices() async throws -> [Voice]
```

`synthesize` gives you an `Audio` value to save or feed elsewhere. `speak` plays it and hands
back a `SpeechHandle`. `synthesizeStream` is covered in [Streaming TTS](https://docs.runanywhere.ai/swift/tts/stream.md).

## SpeechHandle

```swift theme={"theme":"css-variables"}
let handle = try await RunAnywhere.tts.speak("A long passage of text…")

// Wait for it to finish
await handle.waitForPlayout()

// Or cut it off
await handle.interrupt()

if handle.interrupted { print("stopped early") }
if let error = handle.error { print(error) }
```

`RunAnywhere.tts.stop()` stops whatever is currently speaking, without a handle.

## Options

```swift theme={"theme":"css-variables"}
let audio = try await RunAnywhere.tts.synthesize(
    "Hello",
    options: TtsOptions(voice: "en_US-amy-medium", speed: 1.1)
)
```

| Field | Type | Default |
| - | - | - |
| `voice` | `String?` | none, model default |
| `language` | `String` | proto default |
| `speed` | `Float` | proto default |
| `pitch` | `Float` | proto default |
| `format` | `RAAudioFormat` | proto default |
| `sampleRate` | `Int` | proto default |

See [Voices](https://docs.runanywhere.ai/swift/tts/voices.md) for choosing one.

## Saving to a file

```swift theme={"theme":"css-variables"}
let audio = try await RunAnywhere.tts.synthesize("Save me")
try audio.samples.write(to: url)
```

`Audio` exposes `duration` alongside its samples.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.