Create speech session

speech.sessions.create(body: SpeechSessionParams): SpeechSession
WSS
/v1/ai/speech/stream

Stream text to our servers and receive generated speech in real-time. Great for latency-sensitive applications and situations where you don't have all the text upfront.

Parameters

voice
string
required

The voice ID to use for speech generation, obtained from 'List voices' API

format
'mp3' | 'pcm_s16le' | 'pcm_f32le' | 'ulaw' | 'webm'

The desired output format of the audio.

language
LanguageCode
return_timestamps
boolean

Controls whether the server will return timestamps for the generated speech

sample_rate
24000 | 16000 | 8000

The desired output audio sample rate

Returns

class SpeechSession: …

Send

sendText(text: string)
void

Send text to the server to append into the text stream.

sendFlush()
number

Force the server to generate speech for all buffered text in the stream.

sendReset()
number

Drop the server's buffered text without generating speech for it.

sendFinish()
void

Inform the server you're done appending text to this session and want it to close when the server has finished dispatching speech.

Receive

SpeechSessionReady
SpeechSessionReady

First message sent by the server, confirming the session is established.

SpeechSessionAudio
SpeechSessionAudio

Binary audio data returned from the server.

SpeechSessionTimestamps
SpeechSessionTimestamps

Timestamps for the audio chunk that was just streamed, if requested in init.

SpeechSessionFlushComplete
SpeechSessionFlushComplete

Acknowledgement that a flush command has been completed.

The nonce matches the one carried by the original flush, allowing you to determine when it has completed.

SpeechSessionResetComplete
SpeechSessionResetComplete

Acknowledgement that a reset command has been completed.

The nonce matches the one carried by the original reset, allowing you to discard any remaining in-flight speech before the reset.

SpeechSessionError
SpeechSessionError

Error envelope returned by the server. Connection closes immediately afterward.