How to access silero vad outputs (speech probabili...
# ask-ai
s
How to access silero vad outputs (speech probability)?
t
Thanks for reaching out, Daniel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you access the Silero VAD outputs, especially the speech probability, which you can find in the
VADEvent
emitted during audio processing. When the VAD analyzes audio frames, it emits events like
INFERENCE_DONE
that carry the speech probability value. Here's a friendly example in Python to guide you:
Copy code
from livekit.plugins import silero
from livekit.agents import vad
import asyncio

# Load the VAD model
vad_model = silero.VAD.load()

# Create a VAD stream
vad_stream = vad_model.stream()

# Process audio frames and listen for events
async def process_vad_events():
    async for event in vad_stream:
        if event.type == vad.VADEventType.INFERENCE_DONE:
            # Access the speech probability
            speech_probability = event.probability
            print(f"Speech probability: {speech_probability}")

# Push audio frames to the stream
# vad_stream.push_frame(audio_frame)
If you prefer TypeScript, here’s how you can do it:
Copy code
import { VAD } from '@livekit/agents-plugins-silero';
import { VADEventType } from '@livekit/agents';

// Load the VAD model
const vad = await VAD.load();

// Create a VAD stream
const vadStream = vad.stream();

// Listen for VAD events
for await (const event of vadStream) {
    if (event.type === VADEventType.INFERENCE_DONE) {
        // Access the speech probability
        const speechProbability = event.probability;
        console.log(`Speech probability: ${speechProbability}`);
    }
}
The
probability
in the
VADEvent
gives you the speech probability, ranging from 0.0 to 1.0. Please don’t hesitate to reach out if you have any questions or need more help—I’m here for you! Sources: agents/src/vad.ts | livekit-plugins/livekit-plugins-turn-detector/README.md | complex-agents/vision/README.md
s
In python, where should this code go? How to connect it to the AgentSession?
t
To connect the Silero VAD processing code to the
AgentSession
in Python, you’ll want to start by initializing the
AgentSession
with an instance of the Silero VAD plugin. I’m here to guide you through it step-by-step: 1. First, install the Silero VAD plugin:
Copy code
pip install livekit-plugins-silero
2. Next, load the VAD model and set it up like this:
Copy code
from livekit.plugins import silero

vad_model = silero.VAD.load(
    min_speech_duration=0.05,
    min_silence_duration=0.55,
    sample_rate=16000,
    activation_threshold=0.5
)
3. Then, pass the VAD instance to the
AgentSession
when creating your agent:
Copy code
from livekit.agents.voice import Agent, AgentSession

agent = Agent(
    instructions="You are a helpful assistant.",
    stt="assemblyai/universal-streaming",
    llm="openai/gpt-4.1-mini",
    tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
    vad=vad_model  # Connect Silero VAD here
)

session = AgentSession()
await session.start(agent=agent, room=ctx.room)
Alternatively, if you prefer, you can also pass the VAD directly when creating the
AgentSession
like this:
Copy code
session = AgentSession(vad=silero.VAD.load())
await session.start(agent=agent, room=ctx.room)
If any part of this feels unclear or you’d like me to walk you through it further, please don’t hesitate to ask—I’m happy to help! Sources: Silero VAD plugin | LiveKit Docs | livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/__init__.py | complex-agents/ivr-agent/agent.py