pls fix ValueError: STTs do not support streaming...
# ask-ai
b
pls fix ValueError: STTs do not support streaming: livekit.plugins.openai.stt.STT. Provide a VAD to enable stt.StreamAdapter automatically or wrap them with stt.StreamAdapter before using this adapter
t
Thanks for reaching out, RikuKomiya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error happens because the OpenAI STT plugin in LiveKit doesn’t natively support streaming input. No worries though! To fix this, you can wrap the OpenAI STT instance with a
stt.StreamAdapter
and include a Voice Activity Detection (VAD) instance. This way, the system can smartly detect when someone is speaking and process the audio segments for transcription. Here’s a friendly example of how you can do this using Python and the Silero VAD:
Copy code
import asyncio
import logging
from livekit import rtc
from livekit.agents import JobContext, WorkerOptions, cli, stt, transcription
from livekit.plugins.openai import stt as openai_stt
from livekit.plugins import silero

logger = logging.getLogger("agent")

async def entrypoint(ctx: JobContext):
    stt_impl = openai_stt.STT()

    if not stt_impl.capabilities.streaming:
        stt_impl = stt.StreamAdapter(
            stt=stt_impl,
            vad=silero.VAD.load()
        )

    async def transcribe_track(participant: rtc.RemoteParticipant, track: rtc.Track):
        audio_stream = rtc.AudioStream(track)
        stt_forwarder = transcription.STTSegmentsForwarder(
            room=ctx.room, participant=participant, track=track
        )

        stt_stream = stt_impl.stream()
        asyncio.create_task(_forward_transcription(stt_stream, stt_forwarder))

        async for ev in audio_stream:
            stt_stream.push_frame(ev.frame)

    @ctx.room.on("track_subscribed")
    def on_track_subscribed(track: rtc.Track, publication: rtc.TrackPublication, participant: rtc.RemoteParticipant):
        if track.kind == rtc.TrackKind.KIND_AUDIO:
            asyncio.create_task(transcribe_track(participant, track))

    await ctx.connect(auto_subscribe=rtc.AutoSubscribe.AUDIO_ONLY)

async def _forward_transcription(stt_stream: stt.SpeechStream, stt_forwarder: transcription.STTSegmentsForwarder):
    async for ev in stt_stream:
        if ev.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
            logger.info(f"Transcript: {ev.alternatives[0].text}")
        stt_forwarder.update(ev)

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
This approach helps the OpenAI STT handle streaming audio gracefully by buffering and segmenting it using VAD. If you have any questions or want me to walk you through any part of this, just let me know—I’m here to help! Sources: agents/src/stt/stream_adapter.ts | Speech-to-text (STT) models | LiveKit Docs | main.py | livekit-agents/livekit/agents/voice/agent.py