boundless-truck-87206
08/03/2025, 1:09 PMtall-airline-16756
08/03/2025, 1:09 PMtall-airline-16756
08/03/2025, 1:09 PMstt.StreamAdapter, you will need to follow these steps:
1. Import the necessary modules:
from livekit.agents.stt import StreamAdapter
from livekit.plugins import your_stt_provider, your_vad_provider
2. Create an instance of your STT provider:
stt = your_stt_provider.STT()
3. Create a VAD instance:
vad = your_vad_provider.VAD.load()
4. Create a StreamAdapter instance, passing the STT and VAD instances:
adapter = StreamAdapter(stt=stt, vad=vad)
5. Use the stream() method to process audio:
stt_stream = adapter.stream()
Here is an example:
from livekit import agents, rtc
from livekit.plugins import openai, silero
async def process_track(ctx: agents.JobContext, track: rtc.Track):
# Create STT and VAD instances
whisper_stt = openai.STT()
vad = silero.VAD.load()
vad_stream = vad.stream()
# Wrap STT in StreamAdapter
adapter = agents.stt.StreamAdapter(stt=whisper_stt, vad=vad_stream)
# Use the adapter's stream
stt_stream = adapter.stream()
# Process audio frames
audio_stream = rtc.AudioStream(track)
async for audio_event in audio_stream:
stt_stream.push_frame(audio_event.frame)
stt_stream.end_input()
Note that the StreamAdapter requires a VAD to function properly. If you have further questions or need additional help, let me know!