From 836cf60611dd252a5c72608fa38c880d82ab2a87 Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Fri, 16 Jan 2026 15:38:33 -0500 Subject: [PATCH] Fix an issue where Grok Realtime would error out when running with SmallWebRTC transport. The underlying issue was related to the fact that we were sending audio to Grok before we had configured the Grok session with our default input sample rate (16000), so Grok was interpreting those initial audio chunks as having its default sample rate (24000). We didn't see this issue when using the Daily transport simply because in our test environments Daily took a smidge longer than a reflexive (localhost) pure WebRTC connection, so we would only send audio to Grok *after* we had configured the Grok session with the desired sample rate. --- changelog/3480.fixed.md | 1 + src/pipecat/services/grok/realtime/llm.py | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 changelog/3480.fixed.md diff --git a/changelog/3480.fixed.md b/changelog/3480.fixed.md new file mode 100644 index 000000000..9d04545ec --- /dev/null +++ b/changelog/3480.fixed.md @@ -0,0 +1 @@ +- Fixed an issue where Grok Realtime would error out when running with SmallWebRTC transport. diff --git a/src/pipecat/services/grok/realtime/llm.py b/src/pipecat/services/grok/realtime/llm.py index 5e368b62b..e1355ce31 100644 --- a/src/pipecat/services/grok/realtime/llm.py +++ b/src/pipecat/services/grok/realtime/llm.py @@ -752,6 +752,14 @@ class GrokRealtimeLLMService(LLMService): async def _send_user_audio(self, frame): """Send user audio to Grok.""" + # Don't send audio if conversation setup is still pending, as it can + # lead to errors. For example: audio sent before conversation setup + # will be interpreted as having Grok's default sample rate (24000), + # and if that differs from the sample rate we eventually set through + # the conversation setup, Grok will error out. + if self._llm_needs_conversation_setup: + return + payload = base64.b64encode(frame.audio).decode("utf-8") await self.send_client_event(events.InputAudioBufferAppendEvent(audio=payload))