Most "Hindi chatbots" we test fail the same way: a customer says "mera order kahan hai bhaiya," and the bot — built on an English-first speech engine — transcribes garbage and replies in confused English. Over a weekend in July 2025 we built one that doesn't. Sarvam's ASR handles the Hindi and Hinglish speech, OpenAI handles the reasoning and the reply, and the round trip stayed under 2 seconds on a Jio 4G connection in a Lucknow test. Here's the full build — code, the code-switching gotcha that breaks naive setups, and the numbers.
~1.8s
Voice Round-Trip on Jio 4G
11
Indian Languages Sarvam Covers
## The 60-Word Answer
Use Sarvam's Speech-to-Text API to transcribe Hindi/Hinglish audio — it's trained on Indian speech, so it beats English-first ASR on code-switched sentences. Pass the transcript to OpenAI's
chat.completions with a system prompt that says "reply in the same language the user used." For voice replies, send OpenAI's text back through a TTS engine. The whole pipeline is three HTTP calls. The hard part is code-switching, not the wiring.
## Why Not Just Use OpenAI's Whisper for the Speech Part?
Whisper is excellent, but it's trained predominantly on English and major world languages. On real Indian speech — where a sentence switches between Hindi and English mid-clause ("bhaiya mera
delivery kab tak
aayega") — it tends to either over-translate to English or mistranscribe the Hindi.
Sarvam AI, a Bengaluru company, trains specifically on Indian languages and accents. In our side-by-side on 40 recorded support calls, Sarvam's transcripts needed far fewer corrections on Hinglish utterances. That's the entire reason to add a second vendor instead of going all-OpenAI.
The honest caveat: for clean, single-language English audio, Whisper is fine and one fewer vendor. Sarvam earns its place specifically when your callers code-switch — which, for most Indian SMB support lines, they do constantly.
## The Pipeline (3 Pieces)
🎙️
Sarvam Speech-to-Text
Caller audio in, accurate Hindi/Hinglish transcript out. Trained on Indian speech, so code-switching survives instead of collapsing into broken English.
🧠
OpenAI Chat Completions
The transcript becomes the user turn. The model reasons, calls any functions (order lookup, etc.), and writes a reply in the caller's language.
🔊
Text-to-Speech (for voice)
For a voice bot, the reply text goes through Sarvam or another TTS to produce natural Hindi audio. Skip this entirely for a text-only WhatsApp bot.
🌐
Language tag passthrough
Sarvam returns a detected language code. Pass it to the model and the TTS so the whole chain stays in the caller's language. This is the glue that prevents the English-reply bug.
## What You'll Need
- A Sarvam AI API key (sign up at sarvam.ai, free credits to start)
- An OpenAI API key with billing enabled
- Node.js 20+ (Python works identically)
- A few real audio clips of Hindi/Hinglish customer questions to test against — not synthetic ones
- For voice: a way to capture mic audio (a web frontend with
MediaRecorder, or Twilio for phone calls)
- For text: just a WhatsApp or web chat input — skip the audio pieces
## Step 1: Transcribe Hindi/Hinglish Audio With Sarvam
Sarvam's STT endpoint takes an audio file and returns the transcript plus a detected language code. The key parameter is asking it to keep code-switched output faithful rather than forcing a single script.
// transcribe.js
import fs from "fs";
const SARVAM_KEY = process.env.SARVAM_API_KEY;
export async function transcribe(audioPath) {
const form = new FormData();
form.append("file", new Blob([fs.readFileSync(audioPath)]), "audio.wav");
form.append("model", "saarika:v2"); // Sarvam's STT model
form.append("language_code", "hi-IN"); // hint; auto-detect also works
const res = await fetch("https://api.sarvam.ai/speech-to-text", {
method: "POST",
headers: { "api-subscription-key": SARVAM_KEY },
body: form
});
const data = await res.json();
return {
text: data.transcript,
language: data.language_code || "hi-IN"
};
}
The code-switching gotcha: if you hard-set language_code to hi-IN and the caller speaks mostly English, Sarvam may transliterate English words into Devanagari ("delivery" becomes "डिलीवरी"). For mixed-language support lines, let auto-detect run on the first turn, then lock to the detected language for the rest of the call. We learned this the hard way when a bilingual caller's transcript came back as unreadable half-Devanagari.
## Step 2: Reason and Reply in the Caller's Language
The transcript goes to OpenAI. The single most important line in the system prompt is the language-matching instruction. Pass the detected language explicitly — don't make the model guess from the text alone.
// reply.js
import OpenAI from "openai";
const openai = new OpenAI();
export async function generateReply(transcript, language, history = []) {
const system = You are a support assistant for an Indian D2C brand.
The caller's language code is "${language}".
Reply ONLY in that language, in a warm, natural, spoken style.
If the caller mixes Hindi and English (Hinglish), reply in Hinglish too — match their register.
Keep replies to 1–2 short sentences; this will be spoken aloud.;
const res = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: system },
...history,
{ role: "user", content: transcript }
],
temperature: 0.4
});
return res.choices[0].message.content;
}
The "1–2 short sentences" instruction matters more than it looks. Models love long, written-style answers. For a spoken bot, a 60-word reply feels like a lecture. Cap it hard.
## Step 3: Speak the Reply Back (Voice Only)
For a voice bot, the reply text goes through TTS. Sarvam offers Indian-language TTS with natural-sounding voices; you can also use any TTS that supports Hindi.
// speak.js
const SARVAM_KEY = process.env.SARVAM_API_KEY;
export async function speak(text, language = "hi-IN") {
const res = await fetch("https://api.sarvam.ai/text-to-speech", {
method: "POST",
headers: {
"api-subscription-key": SARVAM_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({
inputs: [text],
target_language_code: language,
speaker: "meera",
speech_sample_rate: 16000
})
});
const data = await res.json();
return Buffer.from(data.audios[0], "base64"); // WAV bytes
}
🎙️
Caller speaks (Hinglish)
🧠
OpenAI replies in-language
## Step 4: Verify the Code-Switching Actually Works
1
Pure Hindi: "मेरा ऑर्डर कब तक आएगा?"
Expect a clean Devanagari transcript and a Hindi reply. This is the easy case — if it fails, your API keys or audio format are wrong.
2
Hinglish: "bhaiya mera delivery kab aayega"
This is the real test. Expect a readable mixed transcript and a Hinglish reply ("aapka order kal tak aa jayega, bhaiya"). If the reply comes back in formal English, your language passthrough is broken.
3
Measure latency end-to-end
Log timestamps at each hop. On our Jio 4G test the breakdown was roughly: Sarvam STT ~600ms, OpenAI ~700ms, TTS ~500ms. Total ~1.8s. Anything over 3s feels broken to a caller.
## Common Mistakes
🗣️
Forcing one language
Symptom: bilingual callers get gibberish transcripts. Fix: auto-detect on turn one, then lock the detected code for the rest of the conversation.
📜
Letting the model write essays
Symptom: voice replies that take 15 seconds to speak. Fix: cap replies at 1–2 sentences in the system prompt, hard.
⏱️
Ignoring latency until launch
Symptom: works on your office wifi, lags badly on a customer's 4G. Fix: test on a real mobile connection from day one, measure each hop.
🔇
No fallback for silence/noise
Symptom: empty transcript on a noisy call crashes the flow. Fix: if Sarvam returns empty text, reply "sorry, main sun nahi paaya, dobara boliye."
## When NOT to Build This
Don't add the voice pipeline if your customers are happy typing. A text-only Hindi WhatsApp bot drops the Sarvam STT and TTS calls entirely — it's cheaper, lower-latency, and simpler. Add voice only if your audience genuinely prefers speaking (older users, low-literacy segments, hands-busy contexts like delivery riders). And if your support is purely English, you don't need Sarvam at all — OpenAI alone handles it. Adding a second vendor you don't need is just more to maintain.
## Real Example: A Lucknow Sweet-Shop Voice Line
A family sweet shop in Lucknow wanted phone orders handled in Hindi during festive rush, when their one phone line stayed busy and they lost walk-up-equivalent orders.
We built the voice pipeline above, plugged into a Twilio number. Callers spoke naturally — mostly Hinglish — and the bot took the order, confirmed quantity and pickup time, and logged it to a Google Sheet the counter staff watched. The code-switching handling was the difference: an English-first stack we'd prototyped first mistranscribed "do kilo kaju katli" as nonsense; Sarvam got it right. We later extended this exact pattern into a full
WhatsApp order bot for a sweet shop and a
Twilio + Sarvam voice IVR for a Tally helpdesk.
The same Indian-speech-first thinking runs under
TalkDrill, our in-house English-fluency app — where we cut voice round-trip latency to
740ms on Indian 4G using a similar streaming architecture. Our
mobile development team reuses these voice patterns across client apps.
## Frequently Asked Questions
### Is Sarvam ASR better than OpenAI Whisper for Hindi?
For code-switched Hindi-English speech, yes — Sarvam is trained on Indian languages and accents, so Hinglish survives transcription instead of collapsing into broken English. For clean single-language English audio, Whisper is fine and one fewer vendor. Pick Sarvam specifically when callers mix languages.
### How many Indian languages does Sarvam support?
Sarvam's speech models cover the major Indian languages — Hindi, Tamil, Telugu, Kannada, Malayalam, Bengali, Gujarati, Marathi, Punjabi, Odia, and English, with more added over time. Always check their current docs, since coverage and model versions change.
### What's the latency of a voice chatbot on Indian mobile networks?
In our Jio 4G test in Lucknow the full round trip was about 1.8 seconds — roughly 600ms for speech-to-text, 700ms for the OpenAI reply, and 500ms for text-to-speech. Keep total under 3 seconds or the conversation feels broken to the caller.
### Can I build a text-only Hindi chatbot without the voice parts?
Yes, and you should if your users type. Drop the Sarvam STT and TTS calls and send the typed message straight to OpenAI with the "reply in the user's language" prompt. That's cheaper, faster, and simpler than the full voice pipeline.
### How do I handle a caller who switches languages mid-conversation?
Auto-detect the language on the first turn, then lock to that code for the rest of the call. Switching detection every turn causes flapping and broken transcripts. If a caller genuinely changes language, a fresh call or a "switch language" command resets it cleanly.
### How much does this cost to run per conversation?
A typical 4–6 turn voice conversation costs a few rupees: Sarvam STT/TTS charge per second of audio, OpenAI per token. At
gpt-4o-mini rates, the model is the cheapest piece. Budget ₹3–₹6 per full voice conversation for planning.
Want a Hindi or vernacular voice bot on your number?
We build voice and text chatbots for Indian SMBs that handle Hinglish, code-switching, and regional languages — wired into WhatsApp or a phone line — in 7–10 working days. Typical project: ₹60k–₹1.2L. Suitable if your customers prefer speaking their own language. No slides, just a working demo.
Book a 20-min Call
As
Hrishikesh, our CTO, says: in India, "speaks Hindi" is not a feature — "understands the way people actually mix Hindi and English" is. That's the bar.