- Convert text to speech using ElevenLabs TTS
- Convert audio to text using ElevenLabs speech-to-text
- Generate realtime responses with Mercury 2.5
- Optimize latency using Mercury 2.5 streaming
Run the Voice Assistant
Directly via Google Colab or download the
.ipynb to run it locally in JupyterDependencies
Install packages and import the libraries required for the Mercury 2.5 SDK, ElevenLabs, and audio playback:API Keys
Set up your API keys for both ElevenLabs and Inception Labs.- Create a
.envin this directory - Add your API keys to the
.env:INCEPTION_API_KEYELEVENLABS_API_KEY
.env file.
Initialize Clients
Create the ElevenLabs and Inception (Mercury 2.5) clients:Create Input Audio
We can simulate a user audio input using ElevenLabs text-to-speech model:Transcribe Speech into Text
We then transcribe the audio input using ElevenLabs’ speech-to-text model. We’ll also measure the transcription latency:Get a Response from Mercury 2.5
We send the transcribed text to Mercury 2.5 and measure the response time. We’re usingmercury-2.5 for fast reasoning responses:
Real-time with Streaming
Improve response latency by using Mercury 2.5 streaming. This allows us to receive the first tokens more quickly, reducing user-perceived latency:Streaming Mercury 2.5 Directly to TTS
We’ve optimized Mercury 2.5 streaming and TTS separately. Now we can stream the model response and convert it to audio as soon as we have complete sentences, demarcated by!, ., ?.