I'm trying to access interim transcripts in LiveKi...
# ask-ai
c
I'm trying to access interim transcripts in LiveKit Agents. I have configured Deepgram STT with interim_results=True and smart_format=True, and I can see final transcripts appearing in conversation_item_added events. However, when I register handlers using session.on_interim_transcript = my_handler_function and session.on_final_transcript = my_handler_function, these handlers NEVER get called - no events are received at all. My setup: - AgentSession with turn_detection='stt' - Deepgram STT: deepgram.STT(model='nova-3', interim_results=True, smart_format=True) - Handler registration: session.on_interim_transcript = async def handler(ev): ... The handlers are registered successfully but never receive any events. What is the correct way to receive interim transcript events in LiveKit Agents? Should I be using a different event registration method, or is there additional configuration required for transcript events to flow to these handlers?
t
Thanks for reaching out, Clovis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To receive interim transcript events in LiveKit Agents when using Deepgram STT with
interim_results=True
and
smart_format=True
, you need to listen for
INTERIM_TRANSCRIPT
events from the STT stream. Here’s how you can implement this: Python Implementation:
Copy code
from livekit.plugins.deepgram import STT
from livekit.agents.stt import SpeechEventType, SpeechEvent
from typing import AsyncIterable

# Configure Deepgram STT with interim results and smart formatting
stt = STT(
    interim_results=True,
    smart_format=True,
    # other options...
)

# Create a stream and process events
stt_stream = stt.stream()

async def process_speech_events(stream: AsyncIterable[SpeechEvent]):
    async for event in stream:
        if event.type == SpeechEventType.INTERIM_TRANSCRIPT:
            # Handle interim transcript events
            interim_text = event.alternatives[0].text
            print(f"Interim: {interim_text}")
        elif event.type == SpeechEventType.FINAL_TRANSCRIPT:
            # Handle final transcript events
            final_text = event.alternatives[0].text
            print(f"Final: {final_text}")
JavaScript Implementation:
Copy code
import { STT } from '@livekit/agents-plugin-deepgram';
import { SpeechEventType } from '@livekit/agents';

// Configure Deepgram STT
const stt = new STT({
    interimResults: true,
    smartFormat: true,
    // other options...
});

const stream = stt.stream();

// Process events from the stream
for await (const event of stream) {
    switch (event.type) {
        case SpeechEventType.INTERIM_TRANSCRIPT:
            // Handle interim transcript
            const interimText = event.alternatives[0].text;
            console.log(`Interim: ${interimText}`);
            break;
        case SpeechEventType.FINAL_TRANSCRIPT:
            // Handle final transcript
            const finalText = event.alternatives[0].text;
            console.log(`Final: ${finalText}`);
            break;
    }
}
Key Points: • Ensure that
interim_results
and
smart_format
are set to
true
in your Deepgram STT configuration. • Listen for
INTERIM_TRANSCRIPT
events from the STT stream to handle interim transcripts. • Use the
SpeechEventType
to differentiate between interim and final transcript events. This approach should allow your handlers to receive and process interim transcript events correctly. Sources: livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s... | plugins/deepgram/src/stt.ts | SpeechEventType | LiveKit Agents | Deepgram integration guide | LiveKit Docs