Skip to content

Fix Live API video streaming in Get_started_LiveAPI quickstart#1165

Open
Kenxpx wants to merge 1 commit intogoogle-gemini:mainfrom
Kenxpx:codex/fix-liveapi-vision-streaming
Open

Fix Live API video streaming in Get_started_LiveAPI quickstart#1165
Kenxpx wants to merge 1 commit intogoogle-gemini:mainfrom
Kenxpx:codex/fix-liveapi-vision-streaming

Conversation

@Kenxpx
Copy link
Copy Markdown

@Kenxpx Kenxpx commented Mar 21, 2026

Summary

This updates quickstarts/Get_started_LiveAPI.py to use the explicit Live API video realtime input path and adds a more forgiving realtime activity configuration for mixed audio/video sessions.

Changes

  • send image frames with session.send_realtime_input(video=msg) instead of media=msg
  • configure realtime_input_config with:
    • activity_handling=NO_INTERRUPTION
    • higher speech sensitivity
    • silence_duration_ms=800
    • prefix_padding_ms=300
  • resize screen captures to 1024x1024 before JPEG encoding

Why

Issue #1108 reports that the quickstart can hallucinate visual content and fail to describe the shared screen or camera feed correctly. The current Live API docs describe explicit realtime video input fields, and this patch aligns the sample with that API shape while also giving the session more time to process multimodal input before responding.

Verification

  • python -m py_compile quickstarts/Get_started_LiveAPI.py

@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:quickstarts Issues/PR referencing quickstarts folder labels Mar 21, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue in the Get_started_LiveAPI quickstart where the model would hallucinate visual content or fail to accurately describe screen shares. The changes improve the reliability of video streaming by updating the Live API input path to use the explicit "video" field, enhancing the real-time activity configuration for mixed audio/video sessions, and optimizing screen capture resolution. These adjustments aim to provide the model with more accurate and appropriately processed multimodal input, preventing misinterpretations.

Highlights

  • Live API Video Input: Switched from using a generic "media" parameter to the explicit "video" parameter when sending image frames to the Live API, aligning with the documented API shape.
  • Realtime Activity Configuration: Configured "realtime_input_config" within "LiveConnectConfig" to use "NO_INTERRUPTION" for activity handling and adjusted automatic activity detection settings (higher speech sensitivity, 800ms silence duration, 300ms prefix padding) for improved multimodal session processing.
  • Screen Capture Resizing: Implemented image resizing to 1024x1024 for screen captures before JPEG encoding, optimizing the visual input.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue with video streaming in the Get_started_LiveAPI.py quickstart. The changes, which include updating the API call for sending video frames, adding a more forgiving realtime activity configuration, and resizing screen captures, are well-aligned with the goal of fixing visual content hallucination. The code is clearer and more correct. I've added one suggestion to improve the efficiency of the screen capture implementation by avoiding object re-initialization in a loop.

image_io = io.BytesIO()
img.save(image_io, format="jpeg")
def _capture_screen(self):
sct = mss.mss()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Creating the mss.mss() object inside _capture_screen is inefficient as this method is called in a loop. It's recommended to initialize mss.mss() once and reuse the object.

A good approach would be to initialize it in the __init__ method of the AudioVideoLoop class and store it as an instance variable (e.g., self.sct). You could then use self.sct here.

Example of changes:

# In AudioVideoLoop.__init__
...
self.sct = None
if self.video_mode == "screen":
    self.sct = mss.mss()
...

# In _capture_screen
def _capture_screen(self):
    monitor = self.sct.monitors[0]
    i = self.sct.grab(monitor)
    ...

This would require modifying __init__ as well, but it would improve performance by avoiding repeated object creation.

@Giom-V Giom-V requested a review from thorwebdev March 26, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:quickstarts Issues/PR referencing quickstarts folder status:awaiting review PR awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant