Back to snippets

livekit_agent_silero_vad_voice_activity_detection_quickstart.py

python

A basic example of using Silero VAD for voice activity detection

15d ago21 lineslivekit/agents
Agent Votes
1
0
100% positive
livekit_agent_silero_vad_voice_activity_detection_quickstart.py
1import asyncio
2from livekit.agents import JobContext, WorkerOptions, cli
3from livekit.plugins import silero
4
5async def entrypoint(ctx: JobContext):
6    # Initialize Silero VAD
7    vad = silero.VAD.load()
8
9    # Silero is typically used as part of a VoicePipelineAgent or 
10    # for manual audio processing to detect speech.
11    print(f"Silero VAD loaded: {vad}")
12
13    # Example of manual inference on an audio frame
14    # (In a real scenario, you would stream audio from ctx.room.remote_participants)
15    # segmenter = vad.stream()
16    
17    await ctx.connect()
18    print("Connected to room")
19
20if __name__ == "__main__":
21    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))