Set up your project
Create a project directory
Set up a virtual environment
Install dependencies
Configure the environment
Create a file named.env
in your project directory and add:
Replace the placeholder values with your actual API keys:
- Get your LMNT API key from the LMNT playground
- Set up a LiveKit server or use LiveKit Cloud
- Get your Deepgram API key from Deepgram Console
- Get your OpenAI API key from OpenAI Platform
Create the agent
Create a file namedagent.py
:
Run the agent
Start your agent:Understanding the code
Let’s examine the key components:Agent Class Definition
LMNT TTS Configuration
model
: TTS model (default: “blizzard”)voice
: Voice ID from LMNT’s voice librarylanguage
: Two-letter ISO 639-1 language codetemperature
: Controls expressiveness - lower values (0.3) for neutral speech, higher (1.0) for dynamic rangetop_p
: Controls stability - lower values for consistency, higher for flexibility
Agent Session Pipeline
- Speech recognition with Deepgram Nova-2 model
- Language generation with OpenAI GPT-4o-mini
- Voice synthesis with LMNT
- Voice activity detection for turn-taking
Customize your agent
Try these modifications to enhance your agent:Change the voice
Change the voice
Add multilingual support
Add multilingual support
Configure the TTS for different languages:Update your agent instructions to match the target language.
Fine-tune speech characteristics
Fine-tune speech characteristics
Adjust expressiveness and stability:
temperature
: 0.3 (neutral) to 1.0 (expressive)top_p
: Lower values for consistency, higher for flexibility
Customize the personality
Customize the personality
Modify the agent instructions to change behavior:
Testing your agent
To test your agent:- Make sure your LiveKit server is running
- Clone LiveKit’s frontend example and run it with your livekit room credentials
- Join a room - your agent will automatically connect and start the conversation
- Speak naturally and experience real-time voice interactions