RuntimeError: The STT (livekit.plugins.openai.stt....
# ask-ai
b
RuntimeError: The STT (livekit.plugins.openai.stt.STT) does not support streaming, add a VAD to the AgentTask/VoiceAgent to enable streamingOr manually wrap your STT in a stt.StreamAdapter {"pid": 38555, "job_id": "AJ_JhL5qz3T5mKA"} How do I manually wrap my STT in a stt.StreamAdapter ? I don't want to add a VAD
t
Thanks for reaching out, aile. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To manually wrap your STT in a
stt.StreamAdapter
, you will need to follow these steps: 1. Import the necessary modules:
Copy code
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:
Copy code
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!