shy-article-62777
05/13/2025, 9:41 AMtall-airline-16756
05/13/2025, 9:41 AMtall-airline-16756
05/13/2025, 9:41 AMSTTSegmentsForwarder
class, which provides an interface for delivering transcriptions in real-time. Here are the best practices:
• Set up the forwarder: Create an STTSegmentsForwarder
instance with your room, participant, and track information.
• Stream speech events: Use a speech stream from your STT provider and update the forwarder with speech events as they arrive.
• Handle transcripts: Process both interim and final transcripts appropriately. For example, you can log them or send them to your backend.
Here is a sample implementation:
from livekit.agents import stt, transcription
from livekit.plugins.deepgram import STT
async def _forward_transcription(
stt_stream: stt.SpeechStream,
stt_forwarder: transcription.STTSegmentsForwarder,
):
"""Forward the transcription and log the transcript in the console"""
async for ev in stt_stream:
stt_forwarder.update(ev)
if ev.type == stt.SpeechEventType.INTERIM_TRANSCRIPT:
print(ev.alternatives[0].text, end="")
elif ev.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
print("\n")
print(" -> ", ev.alternatives[0].text)
Let me know if you need further assistance or clarification!
Sources: Tree View: | dse-workbench | Transcriptions | LiveKit Docs | Transcriptions | LiveKit Docsshy-article-62777
05/13/2025, 9:43 AMtall-airline-16756
05/13/2025, 9:43 AMshy-article-62777
05/13/2025, 10:12 AMtall-airline-16756
05/13/2025, 10:12 AM