Skip to main content

Text-to-speech

The selected TTS service is ctx.textToSpeech. It returns a ReadableStream, so consumers can start playback or persistence before the full response arrives.

const speech = await ctx.textToSpeech.synthesize('Welcome aboard.', {
voice: 'alloy',
signal,
})

const response = new Response(speech.audio, {
headers: {'content-type': speech.mediaType},
})

The result includes the audio stream, media type, and model. Consume or cancel the stream: concurrency capacity remains held until the stream completes or is discarded.

voices() returns discoverable voices. An empty list means the provider cannot enumerate them and the UI should allow a manually entered voice ID.

OpenAI-compatible options​

OptionMeaning
voiceVoice ID; overrides the configured default
responseFormatmp3, opus, aac, flac, wav, or pcm
speedSpeaking speed from 0.25 to 4
instructionsDelivery guidance for models that support it
userOptional end-user identifier

Synthesis calls POST /audio/speech. Voice discovery calls GET /audio/voices; HTTP 404 or 405 is treated as unsupported and returns an empty list.