Sarvam AI
Text-to-speech for Indian languages: SarvamTTSService over WebSocket and SarvamHttpTTSService over HTTP.
Overview
SarvamTTSService: streams text over Sarvam's WebSocket and pushes audio as it arrives. Interruptions reconnect the socket.SarvamHttpTTSService: one HTTP request per sentence.
Upstream page
Pipecat's documentation for the same service.
Source
packages/sarvam/src/tts.ts.
Sarvam docs
The text-to-speech API reference.
Installation
bun add @pipedog/sarvamimport { SarvamHttpTTSService, SarvamTTSService } from "@pipedog/sarvam/tts";Prerequisites
- A Sarvam account and an API key from the Sarvam dashboard.
- Pass the key as
apiKey. The examples read it fromSARVAM_API_KEY.
Models
| Model | Pitch and loudness | Temperature | Pace | Sample rate |
|---|---|---|---|---|
bulbul:v3 (default), bulbul:v3-beta | ignored | 0.01 to 1.0 | 0.5 to 2.0 | 24000 Hz by default |
bulbul:v4-flash | supported | ignored | 0.5 to 2.0 | 24000 Hz by default |
TTS_MODEL_CONFIGS holds each model's speakers and limits, and getSpeakersForModel(model) lists
its speakers. Preprocessing is always on for these models. Settings a model doesn't support are
dropped or clamped when the service is constructed.
SarvamTTSService
Configuration
Prop
Type
Settings
Runtime-updatable settings, passed as settings: new SarvamTTSService.Settings({...})
(SarvamTTSSettings). Any setting you leave out keeps the default below.
| Setting | Type | Default | Description |
|---|---|---|---|
model | string | "bulbul:v3" | TTS model. |
voice | string | "shubh" | Speaker. |
language | Language | "en-IN" | Language of the text. |
enablePreprocessing | boolean | null | false | Text preprocessing. Always on for v3 and v4-flash. |
pace | number | null | 1.0 | Speech pace, 0.5 to 2.0. |
pitch | number | null | null | Pitch (bulbul:v4-flash). |
loudness | number | null | null | Volume multiplier (bulbul:v4-flash). |
temperature | number | null | null | Randomness, 0.01 to 1.0 (bulbul:v3; the server's default is 0.6). |
minBufferSize | number | null | 50 | Characters to buffer before generating audio. |
maxChunkLength | number | null | 150 | Largest chunk, in characters, processed at once. |
Usage
import { TTSUpdateSettingsFrame } from "@pipedog/core/frames/frames";
import { Language } from "@pipedog/core/transcriptions/language";
import { SarvamHttpTTSService, SarvamTTSService } from "@pipedog/sarvam/tts";
const tts = new SarvamTTSService({
apiKey: process.env.SARVAM_API_KEY ?? "",
settings: new SarvamTTSService.Settings({
model: "bulbul:v3",
voice: "shubh",
language: Language.HI_IN,
}),
});Change settings mid-call with a TTSUpdateSettingsFrame:
// Queue it on the worker, or push it from a processor upstream of the service.
const update = new TTSUpdateSettingsFrame({
delta: new SarvamTTSService.Settings({ pace: 1.2 }),
});Notes
- The socket carries
config,text,flushandpingmessages. The API key and aUser-Agentgo in the handshake headers. sampleRatecan be 8000, 16000, 22050 or 24000;nulluses the model's default.
SarvamHttpTTSService
Configuration
Prop
Type
Settings
settings: new SarvamHttpTTSService.Settings({...}) (SarvamHttpTTSSettings) takes the same
fields as above except minBufferSize and maxChunkLength, with the same defaults.
Usage
const http = new SarvamHttpTTSService({
apiKey: process.env.SARVAM_API_KEY ?? "",
settings: new SarvamHttpTTSService.Settings({ voice: "shubh", pace: 1.1 }),
});Notes
fetchreplaces the globalfetch(upstream takes an aiohttp session).baseUrldefaults tohttps://api.sarvam.ai. The WAV header of each reply is stripped before the audio is pushed.sampleRatecan also be 32000, 44100 or 48000 forbulbul:v3.
| Runtime | Works | What it needs |
|---|---|---|
| Bun | ✅ yes | Nothing. |
| Node.js | ✅ yes | Nothing. |
| Deno | ✅ yes | Nothing. |
| Cloudflare Workers | ✅ yes | Nothing. |
Generated from pipecat.runtimes and pipecat.compat in packages/sarvam/package.json: ✅ means the compat smoke test passes on that runtime.
Runtime notes
- HTTP goes through
fetchand the WebSocket through the corewebsocketConnect. Both work on Bun, Node, Deno and Cloudflare Workers. bulbul:v2, theInputParamsclass and themodel,voice_id,paramsandaggregate_sentencesconstructor options are deprecated upstream and not ported.- Tested against local servers, not against Sarvam itself.
pipedog is an unofficial community TypeScript port of Pipecat. It is not affiliated with or endorsed by Daily or the Pipecat project.
Portions adapted from the Pipecat documentation, Copyright (c) 2024–2025 Daily, BSD-2-Clause (see apps/docs/LICENSE-pipecat-docs).