Generating Speech

Turn text into speech with voices, delivery directions, and speaker information.

The generateAudio() function turns text into speech through a session-admitted Rust speech binding. Like generateImage(), it returns a file object you can save, publish, or attach to chat. model names a stable manifest alias; the deployment chooses its provider, endpoint, upstream model, credential, and format.

Basic Speech Generation

let narration = generateAudio(
  prompt: "Welcome to the Robot Book Club. Today, we explore the greatest sports plays.",
  model: "narration"
)

"Saved narration: {{narration}}"

The result describes retained audio bytes. OpenAI-compatible and ElevenLabs bindings normally return MP3. Gemini 3.8 returns a complete WAV by default; Kaya preserves that container and wraps raw PCM only when the provider declares it and WAV output is requested. Requested PCM remains headerless. The file is materialized in the session filesystem before the call returns.

Choosing a Voice

Pass a provider voice name or ID as voice. Gemini 3.8 accepts featured voices such as Kore and Puck, plus IDs from Google's extended voice library. Select a regional catalog voice when you want a particular accent; a language hint does not replace the voice's identity.

let line = generateAudio(
  prompt: "We made it! <laugh> What a wonderful day.",
  voice: "Puck",
  model: "quick",
  style: "Happy and excited, with a bright, conversational delivery.",
  format: "wav",
  filename: "celebration.wav"
)

Gemini 3.8: delivery and library voices

The checked Gemini TTS example binds studio to gemini-3.8-flash-tts and quick to gemini-3.8-flash-lite-tts, both through the explicit gemini_interactions connector. Its server, client and job manifests include the speech routes and retained object storage.

Keep prompt as the words to speak. Kaya sends style separately as Google's speech_metadata.style, so sustained emotions, pacing and delivery directions stay outside the transcript. actor names the speaker for the turn and travels as speech_metadata.speaker; it identifies who is speaking, while voice still selects how that speaker sounds. Momentary vocal events belong inside the transcript using angle brackets, such as <laugh>, <sigh> or <short pause>. A binding that cannot honor style or actor fails before dispatch rather than silently dropping the option: OpenAI honors style only, and ElevenLabs honors neither.

let warning = "Wait. <short pause> The bridge is closing. Please come back now."
let audio = generateAudio(
  prompt: warning,
  model: "studio",
  voice: "Kore",
  style: "Urgent and concerned, with clear pronunciation.",
  actor: "guide",
  format: "wav",
  filename: "warning.wav"
)
speak(text: warning, actor: "guide", audio: audio)

speak() adds a semantic speech event with the retained file reference and digest. Playback remains the host's responsibility. To choose an extended voice, the example browses Google's read-only GET /v1beta/voices catalog and passes a returned id unchanged as voice; no voice creation is required.

These provider details were checked on 2026-10-13 against Google's speech guide and voice catalog reference.

Parameters

ParameterTypeDescription
promptstringRequired. Verbatim spoken text, including supported inline vocal events.
modelstringStable speech binding alias; omission requests the admitted default.
voicestringProvider voice name or opaque catalog ID; omission uses the binding's default.
languageCodestringOptional provider language hint. Gemini Interactions maps it to speech_config[].language; omission uses automatic detection.
stylestringOptional delivery directions. Gemini Interactions and OpenAI honor it; ElevenLabs refuses it.
actorstringOptional speaker label. Gemini Interactions only; other bindings refuse it.
formatstringOptional output encoding. Gemini Interactions admits "wav" or "pcm"; omission uses the binding's format.
filenamestringOptional session-relative output path.

Native generateAudio() currently rejects cacheKey, forceCacheMiss and retry. Each fresh call submits one speech request; resuming a retained call settles its existing invocation. Speech credentials come from the selected tool-server connector, such as credential.env: "GEMINI_API_KEY".

Next Steps