Skip to content
Woyce Technologies
AboutTeamCareersContactStart a project →

Voice AI Development with Twilio and Amazon Lex: Setup to Production

How to build a phone-based voice AI bot using Twilio Voice and Amazon Lex — from architecture to production deployment.

Voice AI Development with Twilio and Amazon Lex: Setup to Production — Woyce Technologies

Phone calls are still where customers go when something is urgent, and they're also where many businesses lose them: long hold queues, rigid "press 1 for sales" menus, and missed calls after hours. Voice AI development with Twilio and Amazon Lex is one of the most practical ways to fix that without replacing your phone system. Twilio handles the telephony, Lex handles speech recognition and intent detection, and your own code decides what happens next, so callers can book appointments, check orders, or reach the right person by simply saying what they need.

The catch is that a voice bot that works in a demo often fails on real calls. Latency over two seconds feels like a dropped line, poorly designed slots break on "Thursday at three," and a missing fallback path strands callers who have accents, background noise, or bad signal. Those details decide whether customers trust the bot or hang up.

This guide covers how the call flow works and where latency hides, a four-step setup for Twilio Voice and Amazon Lex, production considerations, a comparison with off-the-shelf IVR products, what the first weeks after launch look like, and the most common mistakes teams make.

How Voice AI Works

When a user calls your business number, Twilio receives the call and streams the audio. Amazon Lex handles automatic speech recognition (ASR) to convert speech to text, then natural language understanding (NLU) to pull out intent. Your backend handles the logic, and Amazon Polly turns the response back into speech.

The flow: caller speaks → Twilio captures audio → Lex ASR + NLU → your logic → Polly TTS → Twilio plays the audio back.

That description sounds simple, but each arrow in that chain hides real decisions. Twilio streams audio as raw audio frames over a WebSocket. Lex processes it in near real-time and can handle interruptions — if a caller starts talking while the bot is speaking, Lex detects barge-in and cuts the playback. Your backend logic needs to respond within a few hundred milliseconds or callers hear dead air, which they interpret as a dropped call. Polly's Neural voices add roughly 80–120 ms of synthesis latency on top of that. In practice, building a voice AI that feels snappy requires profiling each segment of that chain, not just the NLU step.

Latency targets to aim for: end-to-end turn-around under 1.5 seconds from the caller finishing their sentence to hearing the bot's reply. Anything over 2 seconds starts feeling broken to most callers.

One voice bot turn through Twilio audio streaming, Lex speech recognition and intent detection, backend logic, Polly synthesis and playback, targeting under 1.5 seconds end to end.

Benefits of Twilio and Amazon Lex Voice AI

Callers Say What They Need

Menu trees force callers to guess which number matches their problem, and many press zero to reach a person. With Lex handling speech recognition and intent detection, callers simply state the reason for the call in their own words, and the bot routes or resolves it. That removes the most frustrating part of traditional IVR and shortens calls, because nobody has to listen to five options before hearing the right one. When the bot is designed well, callers often finish routine requests in under a minute.

Answers Outside Business Hours

Missed calls after hours often turn into lost bookings or customers who try a competitor. A voice bot answers every call, at any time, and can complete structured tasks such as booking appointments, checking order status, or taking a callback request. Staff arrive the next morning to completed bookings and a queue of well-documented callback requests rather than a list of voicemails to decipher and return. Callers who would have hung up on a voicemail greeting get their request handled on the spot.

Full Control Over Logic and Data

Because your own Lambda code sits between Lex and the caller, you decide exactly what the bot does: which systems it queries, how it validates input, what it says, and when it hands off. Conversation logs live in your AWS account, not a vendor's platform, so you can analyse them, keep them under your own retention rules, and use them to improve the bot. Off-the-shelf IVR products rarely offer that depth of integration or that level of access to raw call data.

Costs That Scale With Calls

Twilio and Lex both charge per use rather than per agent seat, so infrastructure costs rise and fall with call volume instead of being fixed per seat. For businesses with steady inbound traffic, the per-call cost of a bot handling routine requests is a small fraction of staff time spent on the same calls. That makes it practical to automate high-volume, low-complexity calls while keeping people focused on conversations that need judgment, empathy, or authority to make exceptions.

Twilio and Amazon Lex Voice AI Use Cases

Appointment Booking for Clinics and Professional Services

Dental groups, clinics, salons, and law firms take a large share of calls simply to book or change appointments. A Lex bot with intents for scheduling, rescheduling, and cancellation, backed by a Lambda that reads and writes the booking system, handles these end to end. Callers confirm a slot without waiting on hold, and front-desk staff spend their time with people in the building. Ambiguous requests, such as a complex treatment question, transfer to a person with the conversation summary attached.

Order Status and Delivery Questions

Retailers and distributors field repeated "where is my order?" calls. The bot collects an order number or phone number, the Lambda queries the order management system, and Polly reads back a specific answer such as the dispatch date and expected delivery. The problem solved is staff repeatedly looking up the same information; the outcome is an instant, accurate answer for the caller and fewer interruptions for the team. Where an order has a problem, such as a failed delivery, the bot can transfer to a person with the order details already retrieved.

Call Routing and Intake

Many businesses mainly need to get each caller to the right person with the right information. A bot asks what the call is about, captures key details such as account number, practice area, or urgency, and transfers through TaskRouter to the correct queue. For a law firm or service company, this replaces a receptionist's first two minutes on every call and gives the person who answers a clear summary instead of a cold start with an unknown caller.

After-Hours Callback Capture

When nobody is available, the bot can take a structured callback request: name, number, reason, and preferred time. Unlike voicemail, the details arrive as structured data that can be logged in the CRM and prioritised automatically. The outcome is fewer missed opportunities and a faster, better-prepared response the next working day, without staffing the phones overnight. Urgent requests can be flagged and sent to an on-call person by SMS, so genuine emergencies are not left waiting until morning.

Setting Up Twilio Voice with Amazon Lex

Four setup steps for a Twilio and Amazon Lex voice bot: create the Lex bot and intents, buy a Twilio number with a webhook, return TwiML for inbound calls, and handle fulfillment in a Lambda.

Step 1: Create a Lex Bot

In the AWS Console, create an Amazon Lex bot (the Amazon Lex V2 documentation covers bot, intent, and slot configuration in detail) with intents for your use case — BookAppointment, CheckStatus, and a Fallback intent for anything unrecognised. The Fallback isn't optional; it's what catches the long tail of real calls.

Think carefully about slot design before writing a single line of code. If your BookAppointment intent needs a date, time, and service type, you need to define how Lex should prompt for missing slots, what validation looks like, and what happens when a caller says "Thursday at three" without specifying AM or PM. Underdefined slots are where most voice bots break in production. Use slot type prompts like "Would that be 3 in the morning or 3 in the afternoon?" rather than re-asking the open-ended question.

For a 12-person law firm handling intake calls, a well-designed Lex bot might include intents like: ScheduleConsultation, AskAboutPracticeArea, RequestCallback, and OfficeHoursQuery. That covers roughly 70–80% of inbound call volume before a lawyer or paralegal needs to pick up.

Step 2: Create a Twilio Phone Number

In your Twilio console, buy a number and point the voice webhook to your Next.js API route at your domain. The Twilio Voice documentation explains webhooks, TwiML, and speech gathering if you haven't configured a voice number before.

If you are US-based, buying a local number (not a toll-free number) tends to improve answer rates for outbound use cases and looks more familiar on caller ID for inbound. Twilio's number provisioning is instant and costs around $1/month per number. For UK numbers, a standard geographic number (+44 XXXX XXXXXX) works well; Twilio supports those through the same console.

Step 3: Handle Inbound Calls

Create a Next.js API route that returns TwiML. Use twilio.twiml.VoiceResponse to greet callers with an Amazon Polly voice and connect to your Lex websocket endpoint.

Your TwiML should include a brief greeting that sets expectations: "Hi, you've reached [Business Name]. I can help you book an appointment or check your order status. What can I do for you today?" Keep it under 15 words after the business name — longer greetings get interrupted. Use <Gather input="speech dtmf"> rather than just <Gather input="speech"> so DTMF keypad input always works as a fallback.

Step 4: Handle Lex Fulfillment

When Lex recognises an intent with all required slots filled, it calls your fulfillment Lambda. The Lambda books the appointment, checks order status, or whatever the business logic is, then returns a spoken response.

The Lambda response format matters here. Lex v2 fulfillment expects a specific JSON structure with sessionState, messages, and optional requestAttributes. One common mistake is returning a response that looks correct but uses the Lex v1 format — the call fails silently and the caller hears the fallback phrase. Always test fulfillment responses with the Lex console's test chat before wiring up the phone number.

For order status checks, the Lambda needs to query your order management system — Shopify, an internal database, or an API — and respond with real data. "Your order 4421 shipped yesterday and is estimated to arrive Friday" is a useful answer. "Your order is being processed" is not. The difference between those two responses is usually just a database JOIN, but it determines whether customers trust the bot enough to use it again.

Twilio and Amazon Lex Voice AI Best Practices

  • Use Neural voices. Amazon Polly Neural voices (Joanna, Matthew) sound noticeably more natural — the standard voices give the call away as a bot immediately.
  • Implement DTMF fallback. Let users press numbers if speech recognition fails, especially in noisy environments.
  • Log every conversation. Keep transcripts, recognised intents, and slot values for quality review; you'll want this the first time something goes wrong.
  • Add a human escalation intent. Transfer to a live agent via Twilio TaskRouter, and let callers trigger it at any point by saying "speak to someone" rather than only after repeated failures.
  • Budget latency per stage. Measure Twilio streaming, Lex recognition, Lambda execution, and Polly synthesis separately so you know where the time goes. Keep fulfillment Lambdas warm and backend queries fast enough that the full turn stays under about 1.5 seconds.
  • Design slots for how people speak. Write prompts that resolve ambiguity directly ("morning or afternoon?"), use the right locale for your callers, and add custom validation for local formats such as UK phone numbers and postcodes.
  • Confirm before acting. Read back key details, such as appointment time or order number, before committing a booking or change, so a misheard slot is caught on the call rather than discovered later.
  • Disclose the bot up front. A short line such as "You're speaking with our automated assistant" sets expectations, meets disclosure rules where they apply, and makes callers more forgiving when they need to rephrase.

A note on what we've watched go wrong: skipping the fallback and DTMF paths because the demo worked. The demo always works. Real callers have accents, background noise, and bad signal — and an agent that can't gracefully escape to a human or a keypad will end the call abruptly enough to lose the customer.

Off-the-Shelf IVR vs Custom Twilio + Lex Build

This table helps put the build decision in context for business owners who are evaluating whether a custom voice AI is worth the investment compared to buying an off-the-shelf IVR product.

FactorOff-the-shelf IVRCustom Twilio + Lex Build
Setup time1–5 days4–10 weeks
Monthly cost$50–$500/month (vendor-priced)$30–$150/month infrastructure + one-time dev cost
Intent flexibilityFixed menu optionsCustom intents for your exact use cases
CRM / backend integrationOften limited or additional costFull control via Lambda functions
Barge-in supportRare in entry tiersSupported natively in Lex v2
Voice qualityStandard TTSPolly Neural (noticeably more natural)
Fallback to humanUsually availableFull control via Twilio TaskRouter
Conversation loggingVendor-controlledYour AWS account, full access
MaintenanceVendor-managedYour team or agency

The break-even point on a custom build typically lands around 6–9 months when you factor in the reduced cost per call and the avoided per-seat licensing fees of many IVR products. For a business handling 500+ inbound calls per month, that math usually favours a custom build. Under 100 calls per month, an off-the-shelf option is probably fine.

What to Expect in Practice

The first version of a voice bot rarely sounds right until you've tested it with real callers. Internal testing produces a skewed sample — your team knows what to say and how to say it. Real callers ask the same question four different ways, go silent mid-sentence, or start by saying "Hello? Is anyone there?" before stating their actual request.

Intent recognition gauge with thresholds at 80 and 85 percent, what each means, and a note to plan at least two rounds of post-launch tuning.

Plan for at least two rounds of tuning after launch. The first round fixes obvious failures in intent recognition. The second round addresses the subtler patterns: callers who never reach a successful intent, calls that escalate to a human faster than expected, and slots that are consistently misheard (phone numbers and postcodes are especially prone to ASR errors).

For a mid-sized UK dental group with three clinics, a voice bot handling appointment bookings typically needs about three weeks of live call monitoring before slot fill rates stabilise. During that period, the team reviews flagged calls daily — ones where the bot said "I'm sorry, I didn't understand that" more than twice — and either adds training utterances to Lex or adjusts slot prompts. After that initial tuning phase, the bot can reliably handle appointment bookings without staff involvement for roughly 65–70% of calls.

A concrete number worth tracking: intent recognition rate. If Lex correctly identifies the caller's intent on the first attempt less than 80% of the time, the bot needs more training utterances or better slot design. Above 85% first-attempt recognition, most callers will complete their interaction without needing human transfer.

Common Twilio and Amazon Lex Voice AI Mistakes

Ignoring Silence Handling

If a caller pauses mid-sentence (very common when reading out a reference number), Lex may close the turn prematurely. Set the endpointingTimeout to at least 1200 ms for use cases involving numbers or addresses. Too short a timeout produces half-captured reference numbers and frustrated callers repeating themselves; test it with people reading real numbers aloud at a natural pace, including the small hesitations people make when looking something up.

Skipping Error Budgets

Every voice bot needs a defined threshold: how many consecutive failures before the bot transfers to a human? Three failed attempts to recognise an intent should trigger escalation, not a fourth rephrasing. Without a defined budget, the bot keeps apologising and re-asking until the caller gives up, which damages trust more than an honest early handoff. Pass the conversation context to the human agent so the caller does not start again.

Not Testing on Mobile Networks

GSM audio compression sounds different from a landline or VoIP call. ASR accuracy can drop noticeably on compressed mobile audio. Run test calls from mobile networks during QA, not just from your office VoIP. Include calls from cars, streets, and busy rooms, since those are the conditions many real callers are in when they phone.

Launching Without a Monitoring Dashboard

Twilio's logs show call duration and status codes. CloudWatch shows Lambda execution. But neither gives you a single view of: how many callers reached their intent, how many escalated, how many dropped. Build that dashboard before launch, not after the first complaint. Track intent recognition rate, escalation rate, average turn latency, and call completion together, and review them daily during the first weeks after launch.

Talk to us if you want help shipping a Twilio + Amazon Lex voice AI system, or if you just want a second opinion on an architecture you've already drafted.

Frequently Asked Questions

How much does it cost to build a voice AI bot with Twilio and Amazon Lex?

Infrastructure costs are modest — Twilio charges around $0.0085 per minute for inbound calls, and Amazon Lex v2 charges $0.004 per speech request. A business handling 1,000 calls per month averaging 3 minutes each would pay roughly $35–$60/month in platform fees. Development cost is separate and depends on complexity: a single-intent bot (appointment booking only) typically takes 4–6 weeks; a multi-intent system with CRM integration takes 8–12 weeks.

Can Twilio + Amazon Lex handle British accents and UK phone numbers?

Yes, with configuration. Amazon Lex supports UK English as a separate locale (en_GB), which significantly improves ASR accuracy for British accents compared to the default en_US locale. UK phone numbers (11 digits) require custom slot validation because Lex's built-in phone number slot type defaults to US formats. Set up a custom slot type with a regex pattern for UK numbers during the initial build.

What happens when the voice bot cannot understand a caller?

If Lex fails to recognise an intent after repeated attempts, the bot should route the caller to a human agent via Twilio TaskRouter. You define the fallback threshold — typically two or three consecutive mismatches. A well-built system also lets callers say "speak to someone" or "transfer me" at any point, which triggers the escalation immediately rather than waiting for failure.

How long does it take to deploy a production-ready voice bot?

A simple bot — one or two intents, no backend integration — can be deployed in two to three weeks. A production system with appointment booking, CRM writes, and a human escalation path typically takes six to ten weeks including QA and call testing. Plan for another two to four weeks of post-launch tuning based on real call data before the bot performs consistently.

Is Amazon Lex or a GPT-based voice solution better for phone bots?

For structured, task-completion calls (book appointment, check order, update address), Lex performs reliably and costs less per call than LLM-based alternatives. For open-ended conversations where the caller's intent is unpredictable, a large language model layer makes sense — but it adds latency, cost, and more complex guardrails. Most business use cases work best with Lex handling structured intents and a GPT layer only for the genuine free-text edge cases.

Do callers know they are talking to a bot?

With Polly Neural voices, many callers do not immediately identify the system as automated — especially if the opening prompt is concise and the bot responds quickly. However, regulatory guidance in the UK (Ofcom) and in certain US states requires disclosure that a caller is interacting with an automated system, particularly for sales or debt-related calls. For inbound customer service, adding a brief disclosure ("You're speaking with our automated assistant") is good practice regardless of legal requirement.

Can the voice bot integrate with our existing CRM or booking system?

Yes. The Lex fulfillment Lambda is standard Node.js or Python code — it can call any API your CRM exposes. Common integrations include Salesforce, HubSpot, Google Calendar, Calendly, and custom-built booking systems. The main prerequisite is that your system has an API endpoint (REST or GraphQL) that returns data fast enough — Lambda responses need to arrive within about 800 ms to keep the conversation flowing naturally.

Conclusion

Phone callers are often your most urgent customers, and IVR menus and hold queues treat them poorly. A Twilio and Amazon Lex voice bot lets callers state what they need in their own words, with Twilio managing the call, Lex recognising intent and filling slots, a Lambda running your business logic, and Polly speaking the reply.

The parts that decide success are rarely the obvious ones. Keep end-to-end response time under about 1.5 seconds, design slots for how people actually speak, always offer DTMF and a fast route to a human, and log every call so you can tune it. Expect to spend the first few weeks after launch adding training utterances and adjusting prompts based on real calls, with intent recognition rate as the number to watch.

Be realistic about scope. Lex is strong for structured, task-based calls and less suited to open-ended conversation, where an LLM layer adds flexibility along with cost and latency. Very low call volumes may not justify a custom build over an off-the-shelf IVR, and disclosure rules for automated calls vary by country and state.

A good starting point is to list your five most common inbound call reasons and check how many could be resolved with data you already have in a system with an API. When you're ready to build, our voice AI development team can help you design and ship it.

WT

Woyce Technologies

AI & Engineering Team · Woyce

Woyce Technologies builds AI chatbots, LLM integrations, voice AI, and full-stack web applications for businesses in the US, UK, Europe & APAC. Based in Rajkot, Gujarat.

READY TO BUILD?

Let's build something
that actually works.

Tell us about your project. We'll be honest about whether we're the right fit — and if we are, we move fast.