Build a voice agent (TypeScript) · Chapter 15 of 21

Numbers, dates and names, said aloud

By the end of this chapter you can turn what a caller says ("k s chaar chaar ek saat", "shukravaar ko, saadhe das baje") into values Kickstart's systems understand, and make Bolo say booking numbers and phone numbers so that a caller can write them down. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Production
  • 3 tasks
  • TypeScript
  • In the all labs plan

The first 2 chapters of Build a voice agent (TypeScript) are free. This one comes with the all labs plan.

Why you need this

On Kickstart's phone line almost every booking call has a number in it: a booking number, a date, a time, a phone number to call back on. Tejas puts it plainly: "If the number is wrong, everything after it is wrong. And if the caller cannot follow the number, they cannot tell you it is wrong."

Numbers are hard on a voice line in both directions. Coming in, the speech-to-text gives them as words, the way they were said. Going out, a voice reads digits as an amount. Here is Sunita, who wants to cancel her service, with Bolo as it is (it already reads an unsure number back before acting on it; chapter 16 opens that up):

  5.72- 10.00  caller  namaste, mera booking number k s chaar chaar ek saat hai. meri service cancel kar dijiye.
 11.30- 15.00  Bolo    main confirm kar loon aapka booking number k s chaar hazaar chaar sau athaarah hai sahi
 15.46- 18.62  caller  kya? number ek ek karke boliye.
 19.90- 23.60  Bolo    main confirm kar loon aapka booking number k s chaar hazaar chaar sau athaarah hai sahi
 24.06- 24.89  caller  theek hai, dhanyavaad.
outcome: caller_hung_up, not a success
  ✖ KS-4417 (hers) cancelled

Bolo did the careful thing and read the number back. It read "KS-4418" as "k s four thousand four hundred eighteen" (in Hindi). Sunita could not check that against the card in her hand, asked for it digit by digit, got the same again, and gave up. Her service is still booked, and she thinks Kickstart cannot cancel a booking.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    spoken.ts: what the caller said, as values

    Write and export three readers of the words speech-to-text gives (number words from ./numbers.ts).

    bookingId(words): "k s" (or "ks") followed by number words that make four digits, each 0 to 9 one digit and each 10 to 99 two ("chavaalees satrah" is 44 17; "forty four" is one number, 44), as "KS-" and the digits; null when there is no "k s" with four digits after it.

    dateOf(words, today = '2026-11-16') as YYYY-MM-DD: aaj or today is today; kal or tomorrow the next day; parson the day after; a weekday (somvaar to ravivaar, monday to sunday) the next one after today; "N tareekh" day N of this month; "N november" (any month) that day. null when no date is said.

    timeOf(words) as HH:MM, from "N baje": subah N is the morning; dopahar, shaam and raat are after noon (dopahar baarah is 12:00); with none of them 7 to 12 are as said and 1 to 6 in the afternoon. saadhe N is N:30, sava N is N:15, paune N is (N-1):45, dedh baje 13:30, dhaai baje 14:30; "N a m" is the morning and "N p m" the afternoon. null when no time is said.

  2. Task 2

    for-speech.ts: numbers said the way the caller needs them

    Write and export forSpeech(text: string): string, a reply as it should be spoken: every code of 2 to 4 capitals, maybe a dash, and 3 to 6 digits (KS-4417, CMP-7001) becomes its letters and digits one at a time ("K S 4 4 1 7"); every phone number of ten digits in two groups of five (98220 11401, maybe with +91 before it) becomes its digits one at a time with a comma between the groups. Everything else stays as it is: "₹1,199", "18 November" and "10 baje" are read right already.

    The given agent.ts sends every reply through it. Sunita (sunita-mishear) and Rahul, an English caller who cancels his booking, must hear their numbers digit by digit, and both calls must succeed.

  3. Task 3 · interview question

    Interview: round-trip.ts, does the caller hear the number you mean?

    For the text 'Booking KS-4423.', with language 'hi-IN' and then 'en-IN', and each time as written and then as forSpeech(text): make it speech (POST VOICE/v1/speak with JSON { text, language, sample_rate: 16000 }; the body is the audio), make that audio text again (POST it to VOICE/v1/listen?sample_rate=16000; the JSON's text), and read it with bookingId. Print LANGUAGE as written: WORDS -> ID and LANGUAGE for speech: WORDS -> ID (ID is null when bookingId finds none): four lines.

What you will learn

  • Numbers as words: what a speech-to-text gives you, and why Hindi numbers are a list, not a pattern.
  • Reading spoken forms into values: booking numbers (one at a time, in pairs, in English), dates (kal, parson, shukravaar, bees november) and times (saadhe das, paune nau, shaam chaar baje).
  • Writing values for the ear: codes and phone numbers one digit at a time; prices, dates and times left alone.
  • A round trip test: text to speech to text to a value, to prove a caller hears the number you mean.

More in Production

Build "Numbers, dates and names, said aloud" yourself

Kickstart services scooters at the door in Nagpur, and its phone line gets 600 calls a day in Hindi, English and Hinglish. You build Bolo, its voice agent, and measure every call: who it understood, how long callers waited and who it cut off. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Build a voice agent (TypeScript) are free. This one comes with the all labs plan.