Speech to Text quickstart Learn how to convert s...
# ask-ai
b
Speech to Text quickstart Learn how to convert spoken audio into text. This guide will show you how to convert spoken audio into text using the Speech to Text API. U*sing the Speech to Text API* 1 Create an API key Create an API key in the dashboard here , which you’ll use to securely access the API. Store the key as a managed secret and pass it to the SDKs either as a environment variable via an
.env
file, or directly in your app’s configuration depending on your preference. .env
Copy code
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.
Copy code
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:
Copy 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
Copy code
")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
Copy code
python example.py
You should see the transcription of the audio file printed to the console.
t
Thanks for reaching out, Aryan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To use the LiveKit Speech-to-Text (STT) API for converting spoken audio into text, here’s a friendly guide to help you get started: 1. Choose an STT Provider Plugin: LiveKit supports several great providers like Amazon Transcribe, AssemblyAI, Azure AI Speech, ElevenLabs, and more. Each one requires its own API key, so pick the one that fits your needs best. 2. Set Up Authentication: You'll want to configure the API key for your chosen provider as an environment variable. For example, if you’re using ElevenLabs, just set
ELEVEN_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:
Copy code
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