if i want my agent to forward transcriptions to my...
# ask-ai
s
if i want my agent to forward transcriptions to my backend, what's; the best practice way to go about this?
t
Thanks for reaching out, A. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To forward transcriptions to your backend in LiveKit, you can use the
STTSegmentsForwarder
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:
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,
):
    """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 Docs
s
I only want it when the user has hanged up or the agent ends the conversation
t
Thank you for clarifying! Unfortunately, I couldn't find specific documentation on forwarding transcriptions only after a user hangs up or an agent ends the conversation. However, you could potentially implement a custom solution by monitoring the call state and triggering the transcription forwarding process when the call ends. If you'd like, I can escalate this to a human specialist for further assistance. Please let me know how you'd like to proceed!
s
i only want it when the conversation ends
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.