|
| 1 | +# ElevenLabs TTS and STT Example |
| 2 | + |
| 3 | +This directory contains an example demonstrating how to use the ElevenLabs TTS and Scribe v2 STT plugins with Vision Agents. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This example creates an AI agent that uses ElevenLabs' state-of-the-art voice technology for both speech synthesis and recognition. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **ElevenLabs TTS**: High-quality, natural-sounding text-to-speech with customizable voices |
| 12 | +- **ElevenLabs Scribe v2**: Real-time speech-to-text with low latency (~150ms) and 99 language support |
| 13 | +- **GetStream**: Real-time communication infrastructure |
| 14 | +- **Smart Turn Detection**: Natural conversation flow management |
| 15 | +- **Gemini LLM**: Intelligent response generation |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +1. Install dependencies: |
| 20 | +```bash |
| 21 | +cd plugins/elevenlabs/example |
| 22 | +uv sync |
| 23 | +``` |
| 24 | + |
| 25 | +2. Create a `.env` file with your API keys: |
| 26 | +```bash |
| 27 | +# Required for ElevenLabs TTS and STT |
| 28 | +ELEVENLABS_API_KEY=your_elevenlabs_api_key |
| 29 | + |
| 30 | +# Required for GetStream (real-time communication) |
| 31 | +STREAM_API_KEY=your_stream_api_key |
| 32 | +STREAM_API_SECRET=your_stream_api_secret |
| 33 | + |
| 34 | +# Required for Gemini LLM |
| 35 | +GEMINI_API_KEY=your_gemini_api_key |
| 36 | +``` |
| 37 | + |
| 38 | +## Running the Example |
| 39 | + |
| 40 | +```bash |
| 41 | +uv run elevenlabs_example.py |
| 42 | +``` |
| 43 | + |
| 44 | +The agent will: |
| 45 | +1. Connect to the GetStream edge network |
| 46 | +2. Initialize ElevenLabs TTS and Scribe v2 STT |
| 47 | +3. Join a call and greet you |
| 48 | +4. Listen and respond to your voice input in real-time |
| 49 | + |
| 50 | +## Customization |
| 51 | + |
| 52 | +### Voice Selection |
| 53 | + |
| 54 | +You can customize the ElevenLabs voice: |
| 55 | + |
| 56 | +```python |
| 57 | +# Use a specific voice ID |
| 58 | +tts = elevenlabs.TTS(voice_id="your_voice_id") |
| 59 | + |
| 60 | +# Use a different model |
| 61 | +tts = elevenlabs.TTS(model_id="eleven_flash_v2_5") |
| 62 | +``` |
| 63 | + |
| 64 | +### STT Configuration |
| 65 | + |
| 66 | +Customize the speech-to-text settings: |
| 67 | + |
| 68 | +```python |
| 69 | +# Use a different language |
| 70 | +stt = elevenlabs.STT(language_code="es") # Spanish |
| 71 | + |
| 72 | +# Adjust VAD settings |
| 73 | +stt = elevenlabs.STT( |
| 74 | + vad_threshold=0.5, |
| 75 | + vad_silence_threshold_secs=2.0, |
| 76 | +) |
| 77 | +``` |
| 78 | + |
| 79 | +### Turn Detection |
| 80 | + |
| 81 | +Adjust turn detection sensitivity: |
| 82 | + |
| 83 | +```python |
| 84 | +turn_detection = smart_turn.TurnDetection( |
| 85 | + buffer_in_seconds=2.0, # How long to wait for speech |
| 86 | + confidence_threshold=0.5, # How confident to be before ending turn |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +## ElevenLabs Models |
| 91 | + |
| 92 | +### TTS Models |
| 93 | +- `eleven_multilingual_v2`: High-quality, emotionally rich (default) |
| 94 | +- `eleven_flash_v2_5`: Ultra-fast with low latency (~75ms) |
| 95 | +- `eleven_turbo_v2_5`: Balanced quality and speed |
| 96 | + |
| 97 | +### STT Model |
| 98 | +- `scribe_v2_realtime`: Real-time transcription with 99 language support |
| 99 | + |
| 100 | +## Architecture |
| 101 | + |
| 102 | +``` |
| 103 | +User Voice Input |
| 104 | + ↓ |
| 105 | +ElevenLabs Scribe v2 STT (Real-time transcription) |
| 106 | + ↓ |
| 107 | +Gemini LLM (Generate response) |
| 108 | + ↓ |
| 109 | +ElevenLabs TTS (Synthesize speech) |
| 110 | + ↓ |
| 111 | +User Hears Response |
| 112 | +``` |
| 113 | + |
| 114 | +## Additional Resources |
| 115 | + |
| 116 | +- [ElevenLabs Documentation](https://elevenlabs.io/docs) |
| 117 | +- [ElevenLabs Voice Library](https://elevenlabs.io/voice-library) |
| 118 | +- [Vision Agents Documentation](https://visionagents.ai) |
| 119 | +- [GetStream Documentation](https://getstream.io) |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | + |
| 123 | +### No audio output |
| 124 | +- Verify your `ELEVENLABS_API_KEY` is valid |
| 125 | +- Check your audio device settings |
| 126 | +- Ensure GetStream connection is established |
| 127 | + |
| 128 | +### Poor transcription quality |
| 129 | +- Use 16kHz sample rate audio for optimal results |
| 130 | +- Speak clearly and avoid background noise |
| 131 | +- Adjust `vad_threshold` if needed |
| 132 | + |
| 133 | +### High latency |
| 134 | +- Consider using `eleven_flash_v2_5` for TTS |
| 135 | +- Check your network connection |
| 136 | +- Reduce `buffer_in_seconds` in turn detection |
| 137 | + |
0 commit comments