Target Audience: This guide is designed for developers who are not primarily familiar with Python or its ecosystem, and want to set up Vocode for GenAI voice calls.
Table of Contents
- Introduction to Vocode and Project Tools
- Project Setup and Dependency Management
- Configuring Environment Variables and Ngrok
- Setting Up the Telephony Server
- Creating the Outbound Call Script
- Additional Notes and Troubleshooting
- References
1. Introduction to Vocode and Project Tools
Vocode is a powerful tool for creating AI-powered voice applications. To streamline the development process, we'll use:
- Poetry: For managing project dependencies and virtual environments.
- Pyproject.toml: A configuration file used by Poetry to define project details, Python version, and required libraries.
2. Project Setup and Dependency Management
- Install Poetry: Follow the instructions on the Poetry installation page.
-
Create the Project:
poetry new project-name
-
Activate the Virtual Environment:
poetry config virtualenvs.create true poetry shell
-
Specify the Python Version:
- Open
pyproject.toml
in your project directory. - Add the following under
[tool.poetry.dependencies]
:python = ">=3.9,<3.12"
- Update the lock file:
poetry lock --no-update
- Open
-
Install Dependencies:
poetry add redis^4.5.4 twilio^8.1.0 vocode==0.1.111 vonage^3.5.1 python-dotenv^1.0.0
-
Verify Installation:
- Create
main.py
and add:print("Hello, GenAI")
- Run:
poetry run python main.py
- You should see "Hello, GenAI" printed in the console.
- Create
3. Configuring Environment Variables and Ngrok
-
Create the
.env
File:- Create a
.env
file in your project's root directory. - Add your credentials (replace placeholders with actual values):
BASE_URL= DEEPGRAM_API_KEY= OPENAI_API_KEY= AZURE_SPEECH_KEY= AZURE_SPEECH_REGION= TWILIO_ACCOUNT_SID= TWILIO_AUTH_TOKEN= TWILIO_FROM_NUMBER=
- Create a
-
Set Up Ngrok:
- Install Ngrok from https://ngrok.com/download.
- Set up your Ngrok AuthToken from https://dashboard.ngrok.com/get-started/your-authtoken.
- Run in a separate terminal:
ngrok http 3000
- Copy the provided ngrok URL (e.g.,
https://abcdef123456.ngrok.io
) and paste it as yourBASE_URL
in.env
, removing thehttps://
prefix and trailing slash. - Image of ngrok terminal output
4. Setting Up the Telephony Server
-
Copy the Server Code:
Get the code from this Gist: https://gist.github.com/bajajcodes/5722cade50a9867b98b246a2cb30ced4 and paste it into
main.py
. -
Activate Your Virtual Environment:
poetry shell
-
Run the Server:
poetry run python main.py
-
Start the FastAPI Server (Add to main.py):
import uvicorn if __name__ == "__main__": uvicorn.run(app, host="localhost", port=port)
-
Run the Script Again:
poetry run python main.py
- Image of Uvicorn Server Output
- Image of ngrok accessing localhost server
5. Creating the Outbound Call Script
-
Set Up Redis:
docker run -dp 6379:6379 -it redis/redis-stack:latest
-
Create outbound_call.py:
Copy the code from this Gist: https://gist.github.com/bajajcodes/718b598b26e146c4b6bbc784c1d2b1c0 and paste it into
outbound_call.py
. -
Activate Your Virtual Environment:
poetry shell
-
Run the Script:
poetry run python outbound_call.py
- Image of Script Console Output
- Image of Server Logs
6. Additional Notes and Troubleshooting
-
Ngrok URL: Ensure the
BASE_URL
in.env
matches the ngrok URL. -
Endpoints: Access your FastAPI app at the ngrok URL or your
BASE_URL
. You can test endpoints like/inbound_call
,/events
, and/recordings
usingcurl
or a web browser.
7. References
- Vocode Telephony Server Documentation: https://docs.vocode.dev/open-source/telephony
- Vocode Telephony Server Code: https://github.com/vocodedev/vocode-python/tree/main/apps/telephony_app
Top comments (2)
Thank you so much for this tutorial.
ThankYou, it is really appreciating.