Build AI Voice Assistant for Restaurants

Step-by-step guide to building an AI voice assistant for the restaurant industry using VideoSDK.

Introduction to AI Voice Agents in the Restaurant Industry

In today's fast-paced world, the restaurant industry is constantly seeking innovative ways to enhance customer experience and streamline operations. One such innovation is the AI

Voice Agent

—a virtual assistant capable of interacting with customers and staff through natural language processing. In this tutorial, we'll explore how to build an AI Voice Assistant specifically tailored for the restaurant industry using the VideoSDK framework.

What is an AI

Voice Agent

?

An AI

Voice Agent

is a software application that can understand and respond to human speech. It uses technologies such as Speech-to-Text (STT), Language Learning Models (LLM), and Text-to-Speech (TTS) to process and generate human-like interactions.

Why are they important for the Restaurant Industry?

AI Voice Agents can significantly enhance the efficiency of restaurant operations. They can handle tasks like taking reservations, answering frequently asked questions, providing menu information, and assisting with order placements. This not only improves customer satisfaction but also allows staff to focus on more complex tasks.

Core Components of a

Voice Agent

  • Speech-to-Text (STT): Converts spoken language into text.
  • Language Learning Model (LLM): Processes the text to understand and generate responses.
  • Text-to-Speech (TTS): Converts text back into speech for the user.

What You'll Build in This Tutorial

In this tutorial, you will build a fully functional AI

Voice Agent

for restaurants using the VideoSDK framework. This agent will be capable of handling basic customer interactions, providing information, and assisting with reservations.

Architecture and Core Concepts

High-Level Architecture Overview

The AI Voice Agent operates through a series of steps: it listens to the user's speech, processes the input to understand the intent, and then generates a spoken response. This process involves several components working in harmony, including the

Cascading pipeline in AI voice Agents

which defines the flow of audio processing.
Diagram

Understanding Key Concepts in the VideoSDK Framework

  • Agent: The core class representing your bot. It defines how the agent behaves and interacts with users.
  • CascadingPipeline: This defines the flow of audio processing, from speech recognition to response generation.
  • VAD & TurnDetector: These components help the agent determine when to listen and when to respond, utilizing

    Silero Voice Activity Detection

    and the

    Turn detector for AI voice Agents

    .

Setting Up the Development Environment

Prerequisites

Before you begin, ensure you have Python 3.11+ installed on your system. You'll also need a VideoSDK account, which you can create at app.videosdk.live.

Step 1: Create a Virtual Environment

To keep your project dependencies organized, it's recommended to create a virtual environment:
1python -m venv myenv
2source myenv/bin/activate  # On Windows use `myenv\\Scripts\\activate`
3

Step 2: Install Required Packages

Install the necessary packages using pip:
1pip install videosdk-agents videosdk-plugins
2

Step 3: Configure API Keys in a .env file

Create a .env file in your project directory and add your VideoSDK API keys:
1VIDEOSDK_API_KEY=your_api_key_here
2

Building the AI Voice Agent: A Step-by-Step Guide

Here is the complete code for the AI Voice Agent. We'll break it down in the following sections to explain each part.
1import asyncio, os
2from videosdk.agents import Agent, AgentSession, CascadingPipeline, JobContext, RoomOptions, WorkerJob, ConversationFlow
3from videosdk.plugins.silero import SileroVAD
4from videosdk.plugins.turn_detector import TurnDetector, pre_download_model
5from videosdk.plugins.deepgram import DeepgramSTT
6from videosdk.plugins.openai import OpenAILLM
7from videosdk.plugins.elevenlabs import ElevenLabsTTS
8from typing import AsyncIterator
9
10# Pre-downloading the Turn Detector model
11pre_download_model()
12
13agent_instructions = "You are a friendly and efficient AI Voice Assistant designed specifically for the restaurant industry. Your primary role is to assist restaurant staff and customers by providing quick and accurate information. You can handle tasks such as taking reservations, answering frequently asked questions about the menu, providing information on restaurant hours and location, and assisting with order placements. However, you are not capable of processing payments or handling sensitive customer data. Always ensure to maintain a polite and professional tone, and remind users to contact restaurant staff for any issues beyond your capabilities. You must include a disclaimer that you are an AI and not a human representative of the restaurant."
14
15class MyVoiceAgent(Agent):
16    def __init__(self):
17        super().__init__(instructions=agent_instructions)
18    async def on_enter(self): await self.session.say("Hello! How can I help?")
19    async def on_exit(self): await self.session.say("Goodbye!")
20
21async def start_session(context: JobContext):
22    # Create agent and conversation flow
23    agent = MyVoiceAgent()
24    conversation_flow = ConversationFlow(agent)
25
26    # Create pipeline
27    pipeline = CascadingPipeline(
28        stt=DeepgramSTT(model="nova-2", language="en"),
29        llm=OpenAILLM(model="gpt-4o"),
30        tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
31        vad=SileroVAD(threshold=0.35),
32        turn_detector=TurnDetector(threshold=0.8)
33    )
34
35    session = [AI voice Agent Sessions](https://docs.videosdk.live/ai_agents/core-components/agent-session)(
36        agent=agent,
37        pipeline=pipeline,
38        conversation_flow=conversation_flow
39    )
40
41    try:
42        await context.connect()
43        await session.start()
44        # Keep the session running until manually terminated
45        await asyncio.Event().wait()
46    finally:
47        # Clean up resources when done
48        await session.close()
49        await context.shutdown()
50
51def make_context() -> JobContext:
52    room_options = RoomOptions(
53    #  room_id="YOUR_MEETING_ID",  # Set to join a pre-created room; omit to auto-create
54        name="VideoSDK Cascaded Agent",
55        playground=True
56    )
57
58    return JobContext(room_options=room_options)
59
60if __name__ == "__main__":
61    job = WorkerJob(entrypoint=start_session, jobctx=make_context)
62    job.start()
63

Step 4.1: Generating a VideoSDK Meeting ID

To interact with your AI Voice Agent, you'll need a meeting ID. You can generate one using the following curl command:
1curl -X POST \\
2  https://api.videosdk.live/v1/meetings \\
3  -H "Authorization: Bearer YOUR_API_TOKEN" \\
4  -H "Content-Type: application/json" \\
5  -d '{"region":"us"}'
6

Step 4.2: Creating the Custom Agent Class

The MyVoiceAgent class inherits from the Agent class. It defines the behavior of the agent, including how it greets users and exits the session.
1class MyVoiceAgent(Agent):
2    def __init__(self):
3        super().__init__(instructions=agent_instructions)
4    async def on_enter(self): await self.session.say("Hello! How can I help?")
5    async def on_exit(self): await self.session.say("Goodbye!")
6

Step 4.3: Defining the Core Pipeline

The CascadingPipeline is crucial as it defines how audio is processed. It includes components for STT, LLM, TTS, VAD, and the TurnDetector.
1pipeline = CascadingPipeline(
2    stt=DeepgramSTT(model="nova-2", language="en"),
3    llm=OpenAILLM(model="gpt-4o"),
4    tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
5    vad=SileroVAD(threshold=0.35),
6    turn_detector=TurnDetector(threshold=0.8)
7)
8

Step 4.4: Managing the Session and Startup Logic

The start_session function initializes the agent session and manages the connection lifecycle.
1async def start_session(context: JobContext):
2    agent = MyVoiceAgent()
3    conversation_flow = ConversationFlow(agent)
4
5    pipeline = CascadingPipeline(
6        stt=DeepgramSTT(model="nova-2", language="en"),
7        llm=OpenAILLM(model="gpt-4o"),
8        tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
9        vad=SileroVAD(threshold=0.35),
10        turn_detector=TurnDetector(threshold=0.8)
11    )
12
13    session = AgentSession(
14        agent=agent,
15        pipeline=pipeline,
16        conversation_flow=conversation_flow
17    )
18
19    try:
20        await context.connect()
21        await session.start()
22        await asyncio.Event().wait()
23    finally:
24        await session.close()
25        await context.shutdown()
26
The make_context function sets up the room options, and the main block starts the job.
1def make_context() -> JobContext:
2    room_options = RoomOptions(
3        name="VideoSDK Cascaded Agent",
4        playground=True
5    )
6
7    return JobContext(room_options=room_options)
8
9if __name__ == "__main__":
10    job = WorkerJob(entrypoint=start_session, jobctx=make_context)
11    job.start()
12

Running and Testing the Agent

Step 5.1: Running the Python Script

To run your agent, execute the following command in your terminal:
1python main.py
2

Step 5.2: Interacting with the Agent in the Playground

Once the script is running, you'll see a URL in the console. Open this URL in your browser to interact with your AI Voice Agent. You can speak to the agent and it will respond based on the instructions provided.

Advanced Features and Customizations

Extending Functionality with Custom Tools

The VideoSDK framework allows you to extend the functionality of your agent using custom tools. These tools can be added to the pipeline to perform additional tasks.

Exploring Other Plugins

While this tutorial uses specific plugins for STT, LLM, and TTS, the VideoSDK framework supports other options. You can explore these to customize your agent further.

Troubleshooting Common Issues

API Key and Authentication Errors

Ensure your API keys are correctly configured in the .env file. Check for any typos or missing keys.

Audio Input/Output Problems

Verify your microphone and speaker settings. Ensure your system permissions allow access to these devices.

Dependency and Version Conflicts

Make sure all dependencies are installed with compatible versions. Use a virtual environment to avoid conflicts.

Conclusion

Summary of What You've Built

You've successfully built an AI Voice Assistant for the restaurant industry using the VideoSDK framework. This agent can handle basic interactions and assist with common tasks.

Next Steps and Further Learning

Explore the

AI voice Agent core components overview

in the VideoSDK documentation to learn more about customizing and extending your AI Voice Agent. Consider integrating additional features to enhance its capabilities.

Start Building With Free $20 Balance

No credit card required to start.

Want to level-up your learning? Subscribe now

Subscribe to our newsletter for more tech based insights

FAQ