Nov 29, 2026 · @rubarajan
Why I built it
My wife started a new job answering customer calls for a US company. She wanted practice before real callers reached her.Role-playing with me only went so far: I ran out of believable customers quickly, and I couldn't judge her English fairly.
So I built CallCoach, a small web app that runs on her phone. She picks a caller, taps Start call, and talks to an AI customer in a natural voice. When she hangs up, a second AI reads the transcript and writes her a coaching report.
The key design choice is that the AI plays the customer, not the coach. She is the representative. That flip turns a chatbot into a training simulator, and the same design works for any call-center or front-desk role.
It has four parts, built in four phases:
- A caller library. Customer personas, each with a voice, a mood, a reason for calling, and a secret checklist of what will satisfy them.
- Live practice calls. A real-time voice conversation she can interrupt, with a live transcript.
- A coaching report. Scores for her English and her call handling, with her exact words and a better way to say them.
- A caller generator. Describe a caller in one line and the AI writes the whole persona.
How the pieces fit
[embedded content: CallCoach architecture · live call and after the call]
Her phone never talks to a model directly. Everything goes through my server, which holds the API keys and saves the transcript, and the grader runs only after the call ends.
Callers are data, not code
Every practice caller is a persona: a record in MongoDB that is turned into a system prompt at call time. Keeping callers as data means I can add a new scenario from the phone in a minute, without a deploy.
Each persona has these fields:
| Field | What it does in the call |
|---|---|
| Name, scenario, summary | Shown on the caller card so she can pick a call |
| Caller profile | Age, job, family, and the facts of their situation |
| Personality and mood | How patient they are, and what calms them down or winds them up |
| Speaking style | Pace, slang, verbal habits, whether they interrupt |
| Opening line | The first thing they say after her greeting |
| Call reason | What they want, in concrete terms |
| Hidden goal | What she must do or explain before they are satisfied, plus any traps |
| Background knowledge | Facts the caller knows or expects |
| Verification details | Made-up name, date of birth, account number and address |
| Difficulty | Easy, medium or hard |
| Voice | One of 31 text-to-speech voices, grouped by accent |
Turning a persona into a caller
A small function, buildPersonaPrompt, assembles these fields into Markdown sections: Who you are, Personality and mood, How you speak, Why you are calling, and so on. Empty fields are dropped, so a thin persona still makes a clean prompt.
Three parts of that prompt do most of the work:
- The role is stated first and plainly. "You are role-playing a CUSTOMER phoning the customer service line. The person you are speaking with is a representative in training." Without this, models drift into being helpful and start answering their own questions.
- The hidden goal is labelled secret. The caller knows what will satisfy them but must never hint at it. She has to discover it by asking good questions, just like a real call.
- Phone rules. One or two short sentences per turn. No lists, no emojis, no stage directions. Never admit to being an AI. Give verification details one or two at a time, only when asked, and read numbers digit by digit.
Difficulty is a paragraph of behaviour, not a number. Easy is patient and forgives small mistakes. Hard pushes back on vague or scripted answers and calms down only if she acknowledges their feelings, explains clearly and gives next steps.
Version history
Personas get tuned constantly, so every save writes an append-only version. A personaVersions collection holds every edit with who made it and a note, and the personas collection holds the current copy. Restoring an old version copies it forward as a new version, so history is never rewritten. Archiving is also just a version, so it can be undone.
Each call records the persona version it used. That matters later: the coaching report is graded against the exact caller she spoke to, even if I have edited it since. The editor also sends the version it started from, and the server rejects a save if someone saved a newer one in the meantime.
The live call: a WebSocket bridge to a voice agent
A practice call is three WebSocket hops: her phone, my server, and Deepgram's Voice Agent API. The voice agent does the listening, thinking and speaking in one stream, so I never wire speech-to-text, the LLM and text-to-speech together myself.
Why a server sits in the middle
The browser could talk to the voice agent directly, but routing through my Express server buys four things:
- Keys stay secret. The speech and Anthropic API keys never reach the phone.
- Auth and limits. The server checks her login token, a 20-minute cap per call, and 120 practice minutes per day.
- A saved transcript. Every turn is written to MongoDB as it happens, so a dropped call still keeps its transcript.
- Diagnostics. The server counts how many seconds of mic audio arrived and how loud it was.
The protocol is small. The browser sends a JSON start message with its token and persona ID, then raw 16 kHz 16-bit mono audio as binary frames. The server sends back JSON events (ready, transcript, interrupt, hangup, ended, error) and the caller's voice as 24 kHz binary audio.
Configuring the voice agent
When the upstream socket opens, the server sends one Settings message that defines the whole caller:
agent: { listen: { provider: { type: 'deepgram', model: 'flux-general-en', keyterms: keytermsFor(persona), eot_threshold: 0.7 } }, think: { provider: { type: 'anthropic', model: 'claude-haiku-5-5' }, endpoint: { url: 'https://api.anthropic.com/v1/messages', headers: { 'x-api-key': ANTHROPIC_API_KEY } }, prompt: buildPersonaPrompt(persona), functions: [{ name: 'end_call', defer_until_eot: true, ... }] }, speak: { provider: { type: 'deepgram', model: persona.voice } }, } A few choices here matter more than they look:
- Keyterms. The speech recognizer gets a list of domain words plus the caller's name, so jargon is transcribed correctly.
- End-of-turn threshold. 0.7 decides how long the caller waits before replying. Too low and the caller jumps in while she is still thinking.
- A small model for the live caller. Claude Haiku 5.5 keeps reply latency low. The big model is saved for grading, where nobody is waiting on the line.
- Bring your own LLM key. The
endpointblock points the agent at my own Anthropic account.
Interruptions and hanging up
Real callers get interrupted, so the AI caller must stop talking the moment she speaks. The voice agent sends UserStartedSpeaking; the server forwards it as interrupt; the browser stops every queued audio buffer at once.
Hanging up is a tool call. The persona prompt tells the caller to say goodbye and then call end_call. The server waits for the agent's audio to finish, with a 6-second fallback, then sends hangup. The browser lets the goodbye play out before closing the call. Without this, the caller says goodbye and then sits silently on the line.
Audio in the browser
This was the hardest part of the project, and none of it is AI.
- Capture. An
AudioWorkletdownsamples the mic to 16 kHz with a simple box filter and posts 20 ms chunks, plus a level for the on-screen meter. Echo cancellation and noise suppression are on, so the caller doesn't hear itself through the speaker. - Playback. Each incoming chunk becomes an
AudioBufferSourcescheduled right after the previous one, with a 60 ms lead to absorb network jitter. A frame can split a 16-bit sample in half, so the odd byte is carried to the next frame. - iPhone Safari. The audio session is set to
play-and-record. Safari can pause theAudioContextwhen the mic turns on, which leaves the mic silent, so the app resumes it after the mic starts and whenever it is interrupted. A screen wake lock keeps the phone awake during the call. - The wrong microphone. On one PC the browser's default mic was a virtual device that recorded only silence. The app now skips known virtual mics, offers a mic picker with a live level meter, and warns her if it has heard nothing after 6 seconds.
Every call also stores a small diagnostics snapshot: browser, audio context state, mic label and peak level. When she said "it didn't hear me", I could see exactly why without asking her to reproduce it.
The coaching report: an LLM grader with a rubric
When a call ends, the server starts the grader in the background and the call page polls every 4 seconds until the report is ready. The grader is Claude Opus 5.5 at high effort, given a fixed rubric and the full transcript.
What it scores
The English score is five categories, each 0 to 100, combined with fixed weights:
| Category | Weight | What it looks at |
|---|---|---|
| Grammar and sentence structure | 25 | Tenses, articles, prepositions, question forms |
| Vocabulary and word choice | 20 | Natural US business English; phrases that sound odd to American callers |
| Clarity | 20 | Short sentences, one idea at a time, numbers and next steps stated clearly |
| Professional tone and empathy | 20 | Warmth, ownership, hold etiquette, staying calm |
| Fluency | 15 | Filler words, false starts, very long turns |
The model returns the five scores; my code computes the weighted overall score. LLMs are poor at arithmetic and inconsistent at weighting, so the deterministic part stays in code.
Call handling is scored separately, as a checklist rather than a number: greeting, identity verification, understanding the need, accurate answers, empathy, next steps and closing. Each step is done, partly, missed or not applicable. Keeping it apart from the English score means a well-spoken call that skipped verification can't hide behind a high number.
What she actually reads
- A 2–3 sentence summary in simple, warm English.
- 2–3 strengths, with quotes.
- 3–6 improvements, each as You said (her exact words), Try (a better phrasing) and a one-line reason.
- 3–5 phrases to practise, with when to use them.
- Factual concerns: anything she told the caller that looks wrong or risky.
"You said / Try" is the most useful part of the app. A score tells her how she did; seeing her own sentence beside a natural rewrite tells her what to change.
Making the grader trustworthy
- Structured output. The request uses a JSON schema with enums for category keys, checklist steps and statuses, so the UI never parses free text.
- Don't punish the transcriber. The rubric says her lines come from speech-to-text. Punctuation and obvious recognition glitches are ignored. A garbled word may be flagged only as "may have been unclear".
- No invented quotes. Every "You said" must be copied exactly from her lines.
- Grade against the real caller. The grader sees the persona version she spoke to, including its hidden goal and verification record. It can tell whether she checked identity correctly and found what the caller needed.
- Encouragement is in the rubric. Praise what she does well and focus on the few changes that matter most. Her confidence is part of the training.
- Cache the rubric. The long rubric is the cached system prompt; only the transcript changes per call.
- Fail visibly. A refusal or truncated response throws an error and marks the report failed, with a button to retry.
Very short calls are skipped. Under 10 words from her, the report explains why and offers "Score it anyway". With no words at all, it tells her to check her microphone.
The caller generator: one line in, a full persona out
Writing a good persona by hand means filling in a dozen fields. The generator cuts that to a sentence: "an impatient retiree who was charged twice and wants it fixed today, hard". Claude Opus 5.5 expands it into every field, and the draft opens in the normal editor. Nothing is saved until she taps Create caller, so a person always reviews what goes into the library.
The generator's system prompt contains three things:
- A field-by-field brief. What each field means and how the live caller will use it. The hidden goal, for example, must include any traps, like a request the representative has to refuse.
- One finished example persona. A single complete example sets the level of detail and tone better than any amount of description.
- The voice catalogue. All 31 voices with gender, accent and character tags. The model picks the one that fits the caller's age, mood and accent.
The response uses a JSON schema whose voice and difficulty fields are enums, so the model can't invent a voice that doesn't exist. The output then goes through the same sanitizePersona function as a hand-written persona, which trims every field to a maximum length and checks the required ones.
Two safety rules are in the prompt. Verification details must be obviously fictional: 555 phone numbers, example.com emails, made-up addresses. And no real people, companies or product names. Generation is also capped at 30 per user per day, and each run's token usage is logged.
Running it at home
The whole app runs on a Raspberry Pi and a static host.
- Front end. React 19 and Vite, mobile first, with a web app manifest so it installs on her home screen like an app. It is served as static assets from Cloudflare Workers, with single-page-app fallback so deep links work.
- Back end. Express 5 and MongoDB on the Pi, run by systemd and reached through a Cloudflare tunnel. A deploy script packs the API, copies it over, runs
npm ciand the seed script, restarts the service and checks/health. - Sign-in. An email allowlist with no passwords. Signing in returns a random 32-byte token, and only its SHA-256 hash is stored, with a TTL index that expires it after 30 days. Logins are rate-limited per IP, and the allowlist is re-checked on every request, so removing someone signs them out everywhere at once. That is enough for a family app; anything public needs real authentication.
- Cost guardrails. 20 minutes per call, 120 practice minutes per day, and 30 generated callers per day. The voice agent and the LLMs bill per use, so the limits keep a forgotten open call from running up a bill.
What I learned
- Flip the roles. Let the AI play the customer and the human play the professional. It is a simulator, so the human does the hard part.
- The hidden goal makes it realistic. A caller who knows what will satisfy them, but won't say, forces the trainee to ask questions and listen.
- Use two models. A small, fast model on the live call, where latency is felt. A large model at high effort for grading, where nobody is waiting.
- Keep the deterministic parts in code. JSON schemas with enums, weights computed in code, and inputs sanitised the same way whether a person or a model wrote them.
- Audio is the hard part. Most of my debugging was iPhone audio sessions and silent microphones, not prompts. Log diagnostics on every call from the start.
- Treat prompts as versioned data. Personas keep changing. Append-only history and a version stamp on every call make the reports reproducible.
- Ship in usable phases. Phase 1 was sign-in, the caller library and deploy; phase 2 live calls; phase 3 the coaching report; phase 4 the generator and settings. Each phase was useful on its own.
Adapting it for another role
Most of the code is domain-neutral. To train for a different kind of call, change three things:
- The personas, including their hidden goals and the generator's example persona.
- The rubric: the language categories, the call-handling checklist and what counts as an accurate answer.
- The recognizer keyterms, so the speech-to-text expects your jargon.
The WebSocket bridge, the audio code, the version history and the report UI work unchanged for a help desk, a sales line, or a front desk.


