bumpy-student-61140
09/09/2025, 11:04 AM.env file, or directly in your app’s configuration depending on your preference.
.env
ELEVENLABS_API_KEY=<your_api_key_here>
2
Install the SDK
We’ll also use the dotenv library to load our API key from an environment variable.
pip install elevenlabspip install python-dotenv
3
Make the API request
Create a new file named
e`xample.py`
or example.mts, depending on your language of choice and add the following code:
# example.pyimport osfrom dotenv import load_dotenvfrom io import BytesIOimport requestsfrom elevenlabs.client import ElevenLabsload_dotenv()elevenlabs = ElevenLabs( api_key=os.getenv("ELEVENLABS_API_KEY"),)audio_url = ( "
https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3
")response = requests.get(audio_url)audio_data = BytesIO(response.content)transcription = elevenlabs.speech_to_text.convert( file=audio_data, model_id="scribe_v1", # Model to use, for now only "scribe_v1" is supported tag_audio_events=True, # Tag audio events like laughter, applause, etc. language_code="eng", # Language of the audio file. If set to None, the model will detect the language automatically. diarize=True, # Whether to annotate who is speaking)print(transcription)
4
Execute the code
python example.py
You should see the transcription of the audio file printed to the console.tall-airline-16756
09/09/2025, 11:05 AMtall-airline-16756
09/09/2025, 11:05 AMELEVEN_API_KEY.
3. Integrate with AgentSession: To get automatic transcription of audio tracks in a LiveKit room, use the STT plugin within an AgentSession. Here’s a quick example:
from livekit.plugins import soniox
from livekit.agents import AgentSession
session = AgentSession(
stt=soniox.STT(),
# Add LLM, TTS, etc. as needed
)
4. Standalone Usage: If you want to transcribe audio directly, you can use the stream() method to process audio streams and get transcription events in real time.
5. Handle Speech Events: The system will send events like FINAL_TRANSCRIPT when the text is confirmed, and INTERIM_TRANSCRIPT for partial updates along the way.
If you’d like, I’m here to help with any specific provider or integration questions you might have. Just let me know!
Sources: agents/src/stt/stt.ts | Pipeline nodes and hooks | LiveKit Docs | AssemblyAI integration guide | LiveKit Docs | Speech-to-text (STT) integrations | LiveKit Docs | Speech & Audio Processing | livekit/livekit_composite | DeepWiki