From aab98b61a0ce656cdb5dc4a23841b4d442b65d35 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Tue, 11 Mar 2025 11:32:38 -0300 Subject: [PATCH] Fixed issue where sending too many images per second caused Gemini to ignore them. --- src/pipecat/services/gemini_multimodal_live/gemini.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pipecat/services/gemini_multimodal_live/gemini.py b/src/pipecat/services/gemini_multimodal_live/gemini.py index ef49df329..c2791ab97 100644 --- a/src/pipecat/services/gemini_multimodal_live/gemini.py +++ b/src/pipecat/services/gemini_multimodal_live/gemini.py @@ -7,6 +7,7 @@ import asyncio import base64 import json +import time from dataclasses import dataclass from enum import Enum from typing import Any, Dict, List, Mapping, Optional, Union @@ -175,6 +176,7 @@ class GeminiMultimodalLiveLLMService(LLMService): **kwargs, ): super().__init__(base_url=base_url, **kwargs) + self._last_sent_time = 0 self.api_key = api_key self.base_url = base_url self.set_model_name(model) @@ -543,7 +545,13 @@ class GeminiMultimodalLiveLLMService(LLMService): async def _send_user_video(self, frame): if self._video_input_paused: return - # logger.debug(f"Sending video frame to Gemini: {frame}") + + now = time.time() + if now - self._last_sent_time < 1: + return # Ignore if less than 1 second has passed + + self._last_sent_time = now # Update last sent time + logger.debug(f"Sending video frame to Gemini: {frame}") evt = events.VideoInputMessage.from_image_frame(frame) await self.send_client_event(evt)