A simple LiveKit AI voice agent using Speechmatics for STT (Speech-to-Text) and TTS (Text-to-Speech).
We use uv for fast and reliable package management. Follow the installation guide here.
You can verify your installation by running:
uv --versionWe will be using the LiveKit command line interface to quickly get up and running.
🍎 macOS
brew install livekit-cli🐧 Linux
curl -sSL [https://get.livekit.io/cli](https://get.livekit.io/cli) | bash🪟 Windows
winget install LiveKit.LiveKitCLI(If running in console you can skip this step)
lk cloud authThis will open a browser window allowing you to sign in or sign up to LiveKit Cloud and allowing your browser to connect to the agent we will create.
uv init livekit-voice-agent --bare
cd livekit-voice-agentuv add \
"livekit-agents[silero,turn-detector]~=1.2" \
"livekit-plugins-noise-cancellation~=0.2" \
"livekit-plugins-speechmatics" \
"livekit-plugins-openai" \
"python-dotenv" \
"torch"Generate your local environment file:
lk app env > .envThis will create a .env.local file using the API keys and URLs linked to your LiveKit cloud account.
To this file, we will now add API keys for Speechmatics and OpenAI.
Note: Go to the Speechmatics website to sign up and get an API key.
Add these lines to your .env file:
SPEECHMATICS_API_KEY="<Your Speechmatics Key>"
OPENAI_API_KEY="<Your OpenAI Key>"Download, clone, or copy and paste the Python code into a file named speechmatics_agent.py in your project directory.
Run the command to download models for voice activity detection and turn detection:
uv run speechmatics_agent.py download-filesOption A: Run in command line
uv run speechmatics_agent.py consoleOption B: LiveKit Playground (UI) For a friendlier UI, connect it to the LiveKit Playground:
uv run speechmatics_agent.py dev