Is there a way to get the transcript with turn lev...
# ask-ai
s
Is there a way to get the transcript with turn level timestamps? I had streaming implemented but I need transcript per turn
t
Thanks for reaching out, Jawad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you get a transcript with turn-level timestamps in LiveKit, you can take advantage of the TTS-aligned transcription feature available in the Python SDK. This handy feature provides synchronized, timed transcripts at either the word or sentence level, making your experience smoother. Here’s a simple way to set it up: 1. Enable
use_tts_aligned_transcript=True
in your
AgentSession
. This will make sure the agent’s generated speech and the transcript timestamps are perfectly in sync. 2. Override the
transcription_node
method in your agent class to receive
TimedString
objects, which come with
start_time
and
end_time
fields. 3. Make sure your
AgentSession
uses a supported TTS provider, like Cartesia or ElevenLabs, especially if you want word-level timestamps. Here’s an example to guide you:
Copy code
async def transcription_node(self, text: AsyncIterable[str | TimedString], model_settings: ModelSettings) -> AsyncGenerator[str | TimedString, None]:
    async for chunk in text:
        if isinstance(chunk, TimedString):
            print(f"Text: '{chunk}', Start: {chunk.start_time}, End: {chunk.end_time}")
        yield chunk

session = AgentSession(
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=cartesia.TTS(),
    vad=silero.VAD(),
    use_tts_aligned_transcript=True,
)
This setup will give you accurate word-by-word or sentence-by-sentence transcripts with precise timing. If you have any questions or need a hand with anything else, please don’t hesitate to ask—I’m here to help! Sources: Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/metrics/base.py | livekit/livekit_models.pb.go | livekit-protocol/livekit/protocol/models.py | Understanding Transcript Timing in Voice Conversations
s
What you have shared is chunk level transcript. I need turn/sentence level timed transcript instead.
t
I'm glad you're interested in obtaining turn or sentence-level timed transcripts in LiveKit! You can achieve this by using the TTS-aligned transcription feature, which provides beautifully synchronized transcription output with timing at either the word or sentence level, depending on your TTS provider. Here’s a simple way to get started: 1. First, enable
use_tts_aligned_transcript=True
in your
AgentSession
. This helps ensure your transcription is perfectly synced with speech timing. 2. Next, override the
transcription_node
method in your agent class to handle
TimedString
objects. These objects come with
start_time
and
end_time
fields, showing the timing in seconds relative to the start of the turn. Here’s a quick example to guide you:
Copy code
async def transcription_node(self, text: AsyncIterable[str | TimedString], model_settings: ModelSettings) -> AsyncGenerator[str | TimedString, None]:
    async for chunk in text:
        if isinstance(chunk, TimedString):
            print(f"Text: '{chunk}', Start: {chunk.start_time}, End: {chunk.end_time}")
        yield chunk

session = AgentSession(
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=cartesia.TTS(),
    vad=silero.VAD(),
    use_tts_aligned_transcript=True,
)
This setup will help you get sentence-level timing when using supported TTS providers. If you have any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help! Sources: livekit-plugins/livekit-plugins-baseten/livekit/plugins/baseten/stt.py | Pipeline nodes and hooks | LiveKit Docs | Text and transcriptions | LiveKit Docs