Build a Voice Assistant with Conversational AI on a Raspberry Pi
Introduction
In this tutorial you will learn how to build a voice assistant with Conversational AI running on a Raspberry Pi. Just like conventional home assistants like Alexa on Amazon Echo, Google Home, or Siri on Apple devices, your Eleven Voice assistant will listen to a hotword, in our case “Hey Eleven”, and then initiate an ElevenLabs Conversational AI session to assist the user.
Prefer to jump straight to the code?
Find the example project on GitHub.
Requirements
- A Raspberry Pi 5 or similar device.
- A microphone and speaker.
- Python 3.9 or higher installed on your machine.
- An ElevenLabs account with an API key.
Setup
Install dependencies
On Debian-based systems you can install the dependencies with:
Create the project
On your Raspberry Pi, open the terminal and create a new directory for your project.
Create a new virtual environment and install the dependencies:
Install the dependencies:
Now create a new python file called hotword.py
and add the following code:
Agent configuration
Create a new agent
Navigate to Conversational AI > Agents and create a new agent from the blank template.
Set up a server tool
We’ll set up a simple server tool that will fetch the weather data for us. Follow the setup steps here to set up the tool.
Run the app
To run the app, first set the required environment variables:
Then simply run the following command:
Now say “Hey Eleven” to start the conversation. Happy chattin’!
[Optional] Train your custom hotword
Generate training audio
To generate the hotword embeddings, you can use ElevenLabs to generate four training samples. Simply navigate to Text To Speech within your ElevenLabs app, and type in your hotword, e.g. “Hey Eleven”. Select a voice and click on the “Generate” button.
After the audio has been generated, download the audio file and save them into a folder called hotword_training_audio
at the root of your project. Repeat this process three more times with different voices.
Train the hotword
In your terminal, with your virtual environment activated, run the following command to train the hotword:
This will generate the hey_eleven_ref.json
file in the hotword_refs
folder. Now you simply need to update the reference_file
parameter in the HotwordDetector
class in hotword.py
to point to the new reference file and you’re good to go!