Livekit agent에서 사용자 발화 메세지transcription (session m...
# ask-ai
l
Livekit agent에서 사용자 발화 메세지transcription (session message history)하는 부분에서 각 발화 메세지의 start time을 기록하는 방법이 있어?
t
Thanks for reaching out, Dan(송희웅). I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you capture the start time of each utterance message in LiveKit agent transcription (session message history). You can achieve this smoothly by using the TTS-aligned transcription feature, which gives you detailed word-level or sentence-level timing information. Here’s a simple way to get started: 1. Enable TTS-aligned Transcription: Just set
use_tts_aligned_transcript=True
in your
AgentSession
configuration. For example:
Copy code
session = AgentSession(
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=cartesia.TTS(),
    use_tts_aligned_transcript=True,
)
1. Implement the
transcription_node
Method:
In your agent class, define this method to capture the start time of each utterance. The iterator will yield a
TimedString
object, which includes both
start_time
and
end_time
for every word or segment.
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"Utterance: '{chunk.text}', Start Time: {chunk.start_time}")
        yield chunk
This method will help you get precise timing for each transcribed utterance effortlessly. If you have any questions or need help tailoring this to your specific needs, please don’t hesitate to reach out. I’m here to support you! Sources: Text and transcriptions | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real...
l
Tts를 따로 쓰고 있지는 않고 혹시 Openai realtime model에서 사용하는 방법은 없어?
t
I'd love to help you record the start time of each utterance message using the OpenAI real-time model in LiveKit! You can do this by tapping into the
response.audio_transcript.delta
events, which nicely provide timing details for each segment. Here’s a simple way to get this up and running: 1. Handle Transcript Delta Events: You can use the
_handle_response_audio_transcript_delta
method to process the timing info. For example:
Copy code
def _handle_response_audio_transcript_delta(self, event: dict[str, Any]) -> None:
    if (start_time := event.get("start_time")) is not None:
        delta = io.TimedString(event["delta"], start_time=start_time)
        print(f"Utterance: '{delta.text}', Start Time: {delta.start_time}")
1. Configure the RealtimeModel: Just make sure to enable input audio transcription in your model configuration like this:
Copy code
from livekit.plugins.openai.realtime import RealtimeModel
from openai.types import realtime

model = RealtimeModel(
    voice="marin",
    modalities=["audio", "text"],
    input_audio_transcription=realtime.AudioTranscription(
        model="gpt-4o-transcribe",
    ),
)
This setup will include timing information in the transcription events, so you'll be able to capture the start time for each utterance easily. If anything feels unclear or you want to dive deeper, just let me know—I’m here to help! Sources: plugins/openai/src/realtime/api_proto.ts | livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt_v2.py | Understanding Transcript Timing in Voice Conversations | Text and transcriptions | LiveKit Docs