Build a voice agent · Chapter 19 of 21
Recordings, transcripts and privacy
By the end of this chapter you can record a call the way the caller lived it, from nothing but what Bolo sent and received; find card numbers, phone numbers and OTPs in a transcript; bleep them out of the sound; and keep them away from the model and every log they would otherwise reach. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Production
- 4 tasks
- Python
- In the all labs plan
The first 2 chapters of Build a voice agent are free. This one comes with the all labs plan.
Why you need this
Kavita wants to listen to calls. When a caller says "Bolo told me pickup was free", she wants to hear what Bolo really said. When Bolo gets something wrong, Imran wants the call to replay it. Every call centre records its calls for exactly these reasons.
Tejas looks after Kickstart's data, and a recording worries him. Callers say things on the phone they should not: a card number when a payment failed, an OTP they were sent, their phone number. Bolo even asks them never to share a card number, but people read it out anyway, in groups of four, before anyone can stop them. A recording of that call is a copy of the card. So is its transcript. So is the request that sent those words to the model, and the complaint the model logged.
Tejas's rule is short: "Keep the call. Never keep the card." Bolo so far keeps nothing of its own, and it sends every word it hears straight to the model, card numbers included.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
recorder.py: Bolo's own recording
Write class Tape: Tape(line) replaces the line's on_audio, play and clear with functions that also call the old ones, and gives caller(), bolo() and wav(): the caller's frames joined; Bolo's audio placed at max(the call's time, where its queue ends), with whatever had not played by a clear dropped; a stereo WAV at 16 kHz, caller left, Bolo right.
Under if __name__ == "__main__":, record run_call("pandey-price", on_line=...) to pandey.wav and print wrote pandey.wav: CALL_ID, A s of the caller, B s of Bolo, then the line: S s.
- Task 2
redact.py: find the numbers nobody should keep
Write find_numbers(words) (every run of digit words in Hindi or English: 12 or more a card, 10 or 11 a phone, 6 to 9 an otp, fewer kept; each span a dict with kind, start_word, end_word, start and end) and redact(words) (the words joined by spaces, each span replaced by [card], [phone] or [otp]).
- Task 3
bleep.py: bleep the recording
Record run_call("kiran-card") with your Tape, get each channel's words with times from POST VOICE/v1/listen, and write a 1 kHz tone over every span find_numbers finds (20 ms either side). Print caller: and Bolo: with each channel's redacted words, bleeped: KIND START-END s, ... for the caller's spans, then write the stereo WAV to kiran-redacted.wav and print wrote kiran-redacted.wav.
- Task 4 · interview question
Interview: to_the_model.py, where else did it go?
Run run_call("kiran-card", redact=redact) after DELETE VOICE/lab/requests. Print the model was sent: FIRST USER MESSAGE, longest run of digits sent to the model: N (over every user message in GET VOICE/lab/requests), complaint logged: SUMMARY (the last /api/complaints entry in GET VOICE/lab/backend's log), then kiran-card: success or not a success.
What you will learn
- A recording from a media stream: two channels, the caller left and Bolo right.
- The call's clock: where Bolo's audio belongs, given that it is sent faster than it plays.
- What a clear means for a recording: audio the caller never heard.
- Numbers in a transcript: runs of digit words, and which runs are a card, a phone or an OTP.
- Bleeping: replacing the sound of a number with numpy, using the speech-to-text's word times.
- Where a number travels: the model's requests, a tool's arguments, the logs; and redacting before any of them.
- What to keep, and for how long.
More in Production
Build "Recordings, transcripts and privacy" 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 are free. This one comes with the all labs plan.