Skip to content
mentoor

Voice bot on the phone line

For engineers

Speech, realtime voice, telephony, error handling and key management for a phone assistant.

A phone voice bot is a chain: audio comes in, text comes out, a model decides, audio goes back, and every link can fail on its own. This case walks one small bot from first call to launch and shows which skill covers which link.

The case

Brightside Dental is a four-chair clinic with one receptionist, Maria. About a third of calls are the same three requests: book a visit, move a visit, ask opening hours. Maria cannot answer while she treats walk-ins, and callers hang up. The clinic's developer, Tomas, builds a phone assistant on a single inbound number. It must book and move visits, answer simple questions and hand over to Maria when it should. It must never read out a patient's record to a stranger.

Step 1: Get the words right

Phone audio is narrow: 8 kHz, compressed, with traffic and kitchen noise behind it. A general transcription model will hear "Dr. Okafor" as "doctor oh coffer" and "Brightside" as "bright side". Tomas sends clinic names, dentist names and treatment terms as vocabulary hints, and does not upsample the audio, because stretching 8 kHz to 44.1 kHz adds no information. He then measures word error rate on 40 real, consented calls. The overall number looks fine, so he also counts errors on dates, times and names, which are the words that cause wrong bookings.

Step 2: Choose the voice pipeline

Tomas can use one speech-to-speech model or a chain of speech-to-text, a language model and text-to-speech. The chain gives him a text transcript for audit, exact control of the legal opening sentence and the freedom to swap the model. A native audio model is often faster to build and sounds smoother. He picks the chain, writes down why, and sets a budget: the caller should hear the first word of the reply within about 1.5 seconds of stopping. A timing log shows where the time goes.

He also tunes turn detection. A silence timeout that suits "yes" cuts off a caller reading a date of birth digit by digit. The bot waits longer only while it is collecting digits. When the caller interrupts, the bot stops speaking and keeps in its history only the part the caller actually heard.

Step 3: Connect the phone line

A phone number reaches the bot through a SIP trunk or a provider such as Twilio or LiveKit. The line carries 8 kHz mu-law audio, so the text-to-speech output must be converted before it is sent back. The call opens with a fixed sentence: it says the caller is speaking to an AI assistant, that the call is recorded and how to reach a person. Recordings and transcripts get a retention limit. Escalation triggers are explicit: the caller asks for a person, the bot misunderstands twice, or the caller mentions pain, swelling or distress. A warm transfer carries a short summary so Maria does not start from zero.

Step 4: Verify callers

Caller ID can be spoofed, and a cloned voice can fool voice recognition. Before verification the bot gives only general information. To read or change a booking it asks for a detail a stranger would not know, then sends a one-time code by text to the number on file. A booking is never saved before the bot repeats the date and time and the caller says yes.

Step 5: Keep the keys and the bill safe

The provider keys stay on the server. If a browser test page needs a realtime session, the server hands it a short-lived token, never the long-lived key. Each caller number gets a daily minute budget and each call a maximum length, because a bot that keeps a silent line open all night spends real money.

Step 6: Plan for failure

Providers return errors. Rate limit and overload errors are retried with a wait, jitter and a cap, and Tomas turns off the SDK's own retries or the outer loop so the two do not multiply. Bad requests and authentication errors are never retried. Timeouts are short, because a caller will not wait 60 seconds. If the main model is overloaded, a fallback model takes the call, and its output is checked against the same rules: tool schema, confirmation, sentence length.

What goes wrong

  • The overall error rate looks good while the dates are wrong.
  • The bot treats caller ID as proof of identity.
  • A retry loop sits on top of an SDK that already retries.
  • A fallback model skips the confirmation step nobody tested.

Before launch, Tomas plays twenty test calls, including a noisy one, an interrupter and a caller who stays silent. Each step below ties to one skill, and the questions test them against realistic artefacts.

Steps

  1. Fix the words that cause wrong bookings

    Skill: voice-stt-tts

    Send clinic names, dentist names and treatment terms as vocabulary hints. Keep the 8 kHz phone audio as it is. Measure word error rate on real consented calls, then count errors on dates, times and names separately, because those decide whether a booking is right.

    Test calls, week 1
    40 consented calls
    MeasureResult
    Overall word error rate7%
    Errors on dates and times9 of 62
    Errors on dentist names11 of 40
  2. Choose a pipeline and set a latency budget

    Skill: voice-realtime

    Chain speech-to-text, a language model and text-to-speech to get a transcript, control of the legal opening sentence and a swappable model. Budget about 1.5 seconds from the end of the caller's turn to the first reply audio. Wait longer only while collecting digits, and trim interrupted replies to what the caller heard.

  3. Connect the number, disclose and hand over

    Skill: voice-telephony

    Convert text-to-speech output to 8 kHz mu-law for the line. Open every call by saying it is an AI assistant, that the call is recorded and how to reach a person. Escalate on request, repeated misunderstanding or distress, with a short summary for Maria.

    Call opening and escalation rule
    1. Opening: "Thanks for calling Brightside Dental. I am an AI assistant, and this call is recorded. Say person at any time to reach our staff."
    2. Escalate when the caller asks for a person, when two answers in a row fail, or when the caller mentions pain, swelling or distress.
    3. Recordings are deleted after 90 days; transcripts keep no payment or card details.
  4. Verify callers before showing or changing anything

    Skill: voice-telephony

    Treat caller ID as a hint. Before verification the bot gives only general information. Then it asks for a detail a stranger would not know and sends a one-time code to the number on file. It repeats date and time and waits for a spoken yes before saving a booking.

  5. Keep keys on the server and cap usage

    Skill: api-keys

    Provider keys stay on the server. A browser test page receives a short-lived session token minted by an authenticated route. Give each caller number a daily minute budget and each call a maximum length so a silent open line cannot drain the account.

  6. Handle errors and fall back safely

    Skill: api-errors

    Retry rate-limit and overload errors with a wait, jitter and a cap, honouring retry-after, and only at one layer. Never retry bad-request or authentication errors. Use short first-token timeouts. Check the fallback model's output against the same tool schema and confirmation rules.

Skills this scenario uses

Where to study