How can I get the agent transcription? Below is ho...
# ask-ai
h
How can I get the agent transcription? Below is how I’m handling user transcription: @session.on("user_input_transcribed") def on_user_input_transcribed(event: UserInputTranscribedEvent): logger.info(f"Dane użytkownika zostały przetranskrypowane: {event.transcript}, final: {event.is_final}, identyfikator mówcy: {event.speaker_id}")
t
Thanks for reaching out, Lukasz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to get agent transcription working in LiveKit, you’ve got a couple of options—either set it up on the agent side or handle it right from the frontend. Let me walk you through both: Agent-Side Configuration: • If you’re using Python agents, good news! Transcriptions are turned on by default. But if you ever want to switch them off, just set
transcription_enabled=False
in
RoomOutputOptions
. • For JavaScript/Node.js agents, you can enable and tweak agent transcription using
AgentTranscriptionOptions
. This lets you adjust things like speed and tokenization to fit your needs. Frontend Integration: • On the frontend side, the LiveKit SDK has your back. You can listen for transcription events—like in JavaScript, just listen for
RoomEvent.TranscriptionReceived
to grab and work with transcription segments. Need some code snippets or want me to dive deeper? Just give me a shout—I’m here to help! Sources: Text and transcriptions | LiveKit Docs | AgentTranscriptionOptions | LiveKit Agents | Transcriptions | LiveKit Docs | examples/voice_agents/timed_agent_transcript.py
h
I want to display the transcription on the side of the agent console.
t
Hey there! If you want to show transcription right next to the agent console, you can build a transcription component that listens for real-time transcription events and updates the display as things happen. Here’s a simple way to think about it: 1. Frontend Integration: • Use the LiveKit SDK to catch
RoomEvent.TranscriptionReceived
events. • Handle the transcription pieces and update the UI on the fly. 2. Example Implementation: • Make a React component to show the transcriptions. Use a hook to keep track of the transcription data and refresh the display in real-time. • Make sure the UI clearly shows who’s talking—agent or user—for easy reading. • Add auto-scrolling so the newest transcription always appears at the bottom. If you want me to share some code examples or help you out with anything else, just give me a shout! Sources: lib/screens/agent_screen.dart | Text and transcriptions | LiveKit Docs | web/src/hooks/use-agent.tsx | src/transcriptions/TranscriptionTile.tsx | complex-agents/shopify-voice-shopper/shopify-voice-frontend/components/Tran...
h
only python
t
Hey there! If you want to show the transcription on the side of the agent console using Python, you can set up a real-time transcription display pretty easily. Here’s a friendly step-by-step: 1. Capture Transcriptions: • Listen for the
user_input_transcribed
event to grab transcription data as it happens. • Keep updating a variable to hold both the interim and final transcriptions. 2. Display Transcriptions: • Create a handy function to show the transcription right in the console. You can use
textwrap
to neatly format the text and print it out in a clean layout. • If you want, clear the console before each update so it looks tidy and fresh. Here’s an example to get you started:
Copy code
from livekit.agents import AgentSession
import os, textwrap

async def entrypoint(ctx):
    session = AgentSession()
    current_transcript = ""

    @session.on("user_input_transcribed")
    def on_transcript(transcript):
        nonlocal current_transcript
        if transcript.is_final:
            current_transcript += " " + transcript.transcript
        display_transcription(current_transcript)

    await session.start(agent=MyAgent(), room=ctx.room)

def display_transcription(text):
    os.system('clear')
    print("=" * 50)
    print("TRANSCRIPTION CONSOLE")
    print("=" * 50)
    print("\n".join(textwrap.wrap(text, width=80)))
    print("=" * 50)
If you’d like me to walk you through anything else or want more examples, just let me know—I’m here to help! Sources: Transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | complex-agents/shopify-voice-shopper/README.md
h
I want agent transcription not user
t
Hey there! If you want to display agent transcription in Python, you can easily capture and show the transcription as it happens. Here’s a simple way to do it: 1. Capture Agent Transcription: • Use the
STTSegmentsForwarder
class to catch transcription events from the agent. • Handle both interim and final transcriptions so you get real-time updates. 2. Display Transcription: • Print the transcription right to the console or create a custom display function if you want it to look nicer. • You can also save the transcription to a file if you want to keep a record. Example:
Copy code
from livekit.agents import stt, transcription
from livekit.plugins.deepgram import STT

async def _forward_transcription(stt_stream: stt.SpeechStream, stt_forwarder: transcription.STTSegmentsForwarder):
    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)
If you have any questions or want me to walk you through more examples, just let me know—I’m here to help! Sources: complex-agents/teleprompter/cartesia-ink.py | Transcriptions | LiveKit Docs | examples/voice_agents/timed_agent_transcript.py
s
@future-stone-4017
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!