Skip to navigation

Generate Speech

Beta
View as Markdown

Beta. Generates speech in a cloned voice.

Provide exactly one of:

  • voice_id — a saved cloned voice from POST /voices/create (or Content Studio), or
  • ref_audio — a reference audio clip uploaded with this request (optional ref_text transcript).

Sending both returns 400. A saved voice_id avoids re-uploading the clip on every call.

Accepts multipart/form-data.

Base URL: https://api.sarvam.ai. Auth: send your key in the api-subscription-key header (recommended); Authorization: Bearer <key> is also accepted.

The cloned voice is cross-lingual: the reference clip’s language does not need to match language_code.

Billing: charged per character of text against the text_to_speech_voice_cloning API. See the pricing page.

Authentication

api-subscription-keystring
API Key authentication via header

Request

This endpoint expects a multipart form containing an optional file.
voice_idstringOptional

Saved cloned voice ID (svc-{uuid}) from POST /voices/create or Content Studio. Exactly one of ref_audio or voice_id must be provided — sending both returns 400. Prefer voice_id when you already saved the voice so you do not re-upload the clip.

ref_audiofileOptional

Reference audio clip used to clone the voice for this request. Supported formats: WAV, MP3, FLAC, OPUS, AAC, MULAW, ALAW, LINEAR16. WAV is recommended.

Limits: max file size 10 MB; max duration 15 seconds; single speaker. Exactly one of ref_audio or voice_id must be provided — sending both returns 400.

ref_textstring or nullOptional<=500 characters

Optional transcript of ref_audio (max 500 characters). Improves fidelity when provided. Omit or leave empty to let the API transcribe the clip. Ignored when voice_id is used.

textstringRequired1-1000 characters

Text to synthesize in the cloned voice. Native scripts and code-mixed text are supported. Maximum 1000 characters; longer text is rejected with a 400. Split longer input client-side and synthesize it in parts.

language_codeenumRequired

BCP-47 language code for the synthesized output. The cloned voice can speak any supported language, regardless of the reference clip’s language (cross-lingual cloning).

Available Options:

  • as-IN: Assamese
  • bn-IN: Bengali
  • en-IN: English (Indian)
  • gu-IN: Gujarati
  • hi-IN: Hindi
  • kn-IN: Kannada
  • ml-IN: Malayalam
  • mr-IN: Marathi
  • od-IN: Odia
  • pa-IN: Punjabi
  • ta-IN: Tamil
  • te-IN: Telugu
pacedouble or nullOptional0.5-2

Speech speed multiplier. 1.0 is natural speed; 0.5 to 2.0 is accepted. Speed is adjusted without changing pitch. Mutually exclusive with max_audio_duration - sending both returns a 400 error.

output_audio_codecenum or nullOptionalDefaults to wav

Audio codec for the output audio. Default is wav.

  • wav: Uncompressed. Best quality for downstream processing.
  • mp3: Smaller file size; suitable for web playback.
  • flac: Lossless compression.
  • opus: Low-bitrate codec ideal for streaming. When speech_sample_rate is explicitly set with opus, it must be one of 8000, 16000, 24000 or 48000 Hz; when omitted, opus output is returned at the native 24000 Hz.
  • aac: Common in mobile and broadcast.
  • linear16: Raw 16-bit PCM.
  • mulaw / alaw: 8-bit telephony codecs for IVR pipelines.
speech_sample_rateenum or nullOptional

Output sample rate in Hz. Supported values are 8000, 16000, 22050, 24000, 32000, 44100, 48000. If omitted, the API returns 24000 Hz. This is a service-side default: the output is resampled to it, so it does not change with the generating model. Set it to match your downstream pipeline: 8000 for telephony/IVR, 16000 for voice agents, 24000 for web playback, 44100/48000 for broadcast.

enable_qcbooleanOptionalDefaults to false

Run the quality-control pipeline. Off by default. When enabled, the generated audio is transcribed and verified before the response is returned, which adds latency — roughly half a second for single-script text, and several seconds for code-mixed text.

enable_cached_responsesbooleanOptionalDefaults to false

Enable response caching. Coming soon - accepted for forward compatibility, currently ignored.

enable_vadbooleanOptionalDefaults to true

Enable VAD-based silence trimming of the generated audio. Default is true. Applies to single-chunk (short) generations; long text that is split into sentence chunks is returned untrimmed.

enable_text_normalizationboolean or nullOptional

Enable pre-TTS text normalization: numbers, currencies and dates are converted to their spoken form before synthesis (e.g. 9840950950 becomes the spoken digit sequence). Defaults to the server-side setting. Supported for all 12 languages accepted by language_code; any other code passes through unchanged.

min_audio_durationdouble or nullOptional
Minimum output audio duration in seconds. If the generated audio is shorter, it is padded with silence.
max_audio_durationdouble or nullOptional

Maximum output audio duration in seconds. If the generated audio is longer, it is time-stretched to fit. Must be >= min_audio_duration. Silently floored to the reference clip’s duration when the clip is longer. Mutually exclusive with pace - sending both returns a 400 error.

ref_audio_durationdouble or nullOptional

Override for the reference audio duration in seconds. Useful for dubbing/sync scenarios where the model should treat the reference as a specific length.

Response

Successful Response
audio_b64string

Base64-encoded output audio in the requested codec. Decode client-side before playback or storage.

request_idstring
Unique request identifier for debugging and support.
audiostringDeprecated

Alias of audio_b64, same value. Retained for callers written against it; prefer audio_b64.

audio_durationdouble or nullOptional
Duration of the generated audio in seconds.

Errors

400
Bad Request Error
402
Payment Required Error
403
Forbidden Error
422
Unprocessable Entity Error
429
Too Many Requests Error
500
Internal Server Error
502
Bad Gateway Error
503
Service Unavailable Error
504
Gateway Timeout Error