Skip to content

google.realtime.RealtimeModel sends AudioSegmentEnd too late #6421

Description

@filipre

Bug Description

Hi!
I'm a developer at Beyond Presence where we provide a virtual avatar for voice agents, see this setup. We noticed an issue with the Gemini Realtime model where the AudioSegmentEnd is sent too late from either LiveKit or the Google RealtimeModel (Gemini) while OpenAI Realtime works fine. This makes it difficult for us to react on time and sometimes causes lags for the user. On some occasions, there is also a residual audio chunk, too.

Expected Behavior

OpenAI sends audio data like this:

rtc.AudioFrame -> ... -> rtc.AudioFrame -> AudioSegmentEnd

Gemini on the other hand looks like this:

Case A: Without residual audio

rtc.AudioFrame -> ... -> rtc.AudioFrame -> [nothing for several seconds] -> AudioSegmentEnd

Case B: With residual audio

rtc.AudioFrame -> ... -> rtc.AudioFrame -> [nothing for several seconds] -> rtc.AudioFrame -> AudioSegmentEnd

Reproduction Steps

1. Talk to an agent using Gemini Realtime model
2. Notice that all `rtc.AudioFrame` come in really fast except the last one
3. Notice that `AudioSegmentEnd` comes in too late. It should come in right after the last audio chunk.

Operating System

Linux, macOS

Models Used

google.realtime.RealtimeModel

Package Versions

"livekit-agents == 1.6.5",
    "livekit-plugins-bey == 1.6.5",
    "livekit-plugins-google==1.6.5",
    "livekit-plugins-openai>=1.6.5",
    "python-dotenv ~= 1.0",

Session/Room/Call IDs

No response

Proposed Solution

Right after the last audio chunk, a AudioSegmentEnd should be sent to indicate that the audio has finished.

Additional Context

No response

Screenshots and Recordings

I confirmed the issue in our logs. Notice that there is a 4s delay between the last audio chunk and the segment end

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions