DEV Community

Shubham Bajaj
Shubham Bajaj

Posted on

Vocode Setup for GenAI Voice Calls: A Guide for Non-Python Developers

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

  1. Introduction to Vocode and Project Tools
  2. Project Setup and Dependency Management
  3. Configuring Environment Variables and Ngrok
  4. Setting Up the Telephony Server
  5. Creating the Outbound Call Script
  6. Additional Notes and Troubleshooting
  7. 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

  1. Install Poetry: Follow the instructions on the Poetry installation page.
  2. Create the Project:
    poetry new project-name
  3. Activate the Virtual Environment:
    poetry config virtualenvs.create true
    poetry shell
  4. 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
  5. 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
  6. 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.

3. Configuring Environment Variables and Ngrok

  1. 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=
  2. Set Up Ngrok:

4. Setting Up the Telephony Server

  1. Copy the Server Code: Get the code from this Gist: https://gist.github.com/bajajcodes/5722cade50a9867b98b246a2cb30ced4 and paste it into main.py.
  2. Activate Your Virtual Environment:
    poetry shell
  3. Run the Server:
    poetry run python main.py
  4. Start the FastAPI Server (Add to main.py):
    import uvicorn
    
    if __name__ == "__main__":
    uvicorn.run(app, host="localhost", port=port)
  5. Run the Script Again:
    poetry run python main.py
  • Image of Uvicorn Server Output Uvicorn Server Output
  • Image of ngrok accessing localhost server ngrok accessing localhost server

5. Creating the Outbound Call Script

  1. Set Up Redis:
    docker run -dp 6379:6379 -it redis/redis-stack:latest
  2. Create outbound_call.py: Copy the code from this Gist: https://gist.github.com/bajajcodes/718b598b26e146c4b6bbc784c1d2b1c0 and paste it into outbound_call.py.
  3. Activate Your Virtual Environment:
    poetry shell
  4. Run the Script:
    poetry run python outbound_call.py
  • Image of Script Console Output Script Console Output
  • Image of Server Logs 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 using curl or a web browser.

7. References

Top comments (2)

Collapse
 
sahilsuman933 profile image
Sahil Suman

Thank you so much for this tutorial.

Collapse
 
bajajcodes profile image
Shubham Bajaj

ThankYou, it is really appreciating.