How do I handle stt.SpeechEventType.PREFLIGHT_TRAN...
# ask-ai
f
How do I handle stt.SpeechEventType.PREFLIGHT_TRANSCRIPT event? (edited)
t
Thanks for reaching out, Anish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
stt.SpeechEventType.PREFLIGHT_TRANSCRIPT
event is a helpful feature that kicks in when the STT system feels confident enough that a part of the speech is stable and ready to be processed, even before the user finishes speaking. Usually, the LiveKit framework takes care of this automatically, but you also have the option to create your own custom handling by using the
RecognitionHooks
protocol. Here’s a friendly example to show you how you might handle this event:
Copy code
from livekit.agents.voice.audio_recognition import RecognitionHooks

class CustomRecognitionHooks(RecognitionHooks):
    def on_interim_transcript(self, ev, *, speaking=None):
        if ev.type == stt.SpeechEventType.PREFLIGHT_TRANSCRIPT:
            transcript = ev.alternatives[0].text
            confidence = ev.alternatives[0].confidence
            print(f"Preflight transcript: {transcript} (confidence: {confidence})")
            # Add custom logic here, e.g., logging or validation
        super().on_interim_transcript(ev, speaking=speaking)
This way, you can easily process the preflight transcript, decide what to do based on confidence levels, or even connect it with other systems you’re using. If you’d like, I’m here to help with any questions or to guide you through the implementation! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/stt.py | Agent speech and audio | LiveKit Docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki