When i send a text message via sdk.TranscriptionSe...
# ask-ai
f
When i send a text message via sdk.TranscriptionSegment while the agent is speaking the message in the chat history (retrieved with session.history in the backend) goes before the interrupted text of the agent. How can i solve this?
t
Thanks for reaching out, muse. 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 get the chat history looking just right! To make sure your messages appear in the correct order when using
sdk.TranscriptionSegment
and
session.history
, a great way is to sort the transcription segments by their timestamps. The key here is the
firstReceivedTime
property on each
TranscriptionSegment
, which helps keep everything in chronological order. Here’s a simple way to approach it: • Gather all your
TranscriptionSegment
objects. • Sort them based on the
firstReceivedTime
value. • If you’re combining these with chat messages, just merge the lists and sort the whole collection by timestamp. Doing this will make sure your real-time transcriptions and chat messages flow smoothly in the right sequence. If you run into any bumps or want to chat more about it, I’m here to help! Sources: Transcriptions | LiveKit Docs | hooks/useChatAndTranscription.ts | lib/src/context/transcription_context.dart | livekit-compose-components/src/main/java/io/livekit/android/compose/state/t...
f
How do i make sure that my backend is registering time in utc? In the frontend i am already doing that
t
To help your backend register time in UTC smoothly, here’s a friendly approach you can follow: • LiveKit uses the
google.protobuf.Timestamp
type for timestamp fields, which is naturally UTC-based. This means your timestamps won’t be affected by any time zone differences. • When you’re creating timestamps in your backend, try to use UTC explicitly. For instance, if you’re working with Python, using
datetime.datetime.now(datetime.timezone.utc)
will give you the current time in UTC. • Also, make sure that any timestamps you send to LiveKit follow the RFC 3339 format and include the "Z" suffix, which shows they’re in UTC. Following these steps will help keep your backend timestamps perfectly aligned with LiveKit’s UTC system. If you have any questions or need a hand, feel free to ask—I’m here to help! Sources: src/main/proto/google/protobuf/timestamp.proto | examples/frontdesk/calendar_api.py