Skip to navigation

Stream speech

View as Markdown

Generates audio from text using Server-Sent Events (SSE) format. Audio chunks are streamed in real-time as base64-encoded audio. This endpoint is optimized for low-latency applications where audio playback should start as soon as possible.

By default each chunk is PCM F32LE (32-bit float). Send output_format to receive pcm_s16le, pcm_mulaw or pcm_alaw instead, at 8000, 16000, 22050 or 24000 Hz. The stream is always raw audio, so output_format.container must be raw. With output_format, the response also carries X-Audio-Format, X-Audio-Sample-Rate and X-Audio-Channels. See Output Formats.

The response is a stream of SSE events:

  • event: chunk - Contains base64-encoded audio data
  • event: done - Signals completion of audio generation

Each chunk event contains:

  • type: “chunk”
  • status_code: 206 (Partial Content)
  • done: false
  • data: Base64-encoded audio chunk, in the output_format encoding (PCM F32LE by default)
  • step_time: Time taken to generate this chunk in seconds

Authentication

X-API-Keystring

API key for authentication. Example: raya_ABCD1234567890abcdef

Request

This endpoint expects an object.
textstringRequired

The text to convert to speech.

Script notes:

  • Hindi (language: hi) must be in Devanagari script. Romanized Hindi is not supported.
  • For English (en-in, en-us), Indic named entities (names, places, etc.) are pronounced more accurately in Devanagari — e.g. राहुल instead of Rahul. If text is LLM-generated, prompt it to output Indic names in Devanagari even when the rest of the content is in English.
voice_idstringRequired

The ID of the voice to use for synthesis. Use /v1/voices to get available voice IDs. The voice_id must match the model you specify — standard voices only work with "model": "standard", and m1 voices only work with "model": "m1".

languageenumRequired

Language code for the text. Currently supported: hi (Hindi), mr (Marathi), te (Telugu), kn (Kannada), bn (Bengali), as (Assamese), gu (Gujarati), ne (Nepali), ml (Malayalam), ta (Tamil), en (English, used by m1 voices), en-in (Indian English), en-us (US English).

Hindi must be written in Devanagari script (Romanized Hindi is not supported). For English, Indic named entities are best written in Devanagari for accurate pronunciation. More languages are coming soon.

modelenumOptionalDefaults to standard

The synthesis model to use. Each model has its own set of voices — use /v1/voices to find voice IDs for the model you choose.

Important: standard and m1 voices are not interchangeable. Passing a standard voice ID with "model": "m1" (or vice versa) will fail.

Allowed values:
speedfloatOptionalDefaults to 1

Speech speed multiplier (0.5 to 1.5). Changes standard voices only; m1 voices ignore it.

output_formatobjectOptional

Encoding and sample rate of the audio chunks. Only the raw container is accepted on the WebSocket.

Response headers

Cache-ControlstringOptional
ConnectionstringOptional
X-Accel-BufferingstringOptional
X-Audio-FormatstringOptional

Only when output_format is sent. The encoding you asked for.

X-Audio-Sample-RateintegerOptional

Only when output_format is sent. The sample rate of the audio, in Hz.

X-Audio-ChannelsintegerOptional

Only when output_format is sent. Always 1 (mono).

Response

Streaming audio generation started

Errors

400
Bad Request Error
404
Not Found Error
422
Unprocessable Entity Error
500
Internal Server Error