We are using the Gemini Live Translate API for real-time speech-to-speech audio pipelines. In high-load backend environments, managed runtimes (Python/Node.js) introduce garbage collection pauses and single-thread bottlenecks that hinder low-latency audio streaming.
To meet our performance needs, we built a working native C++ client using Boost (Asio/Beast) for low-latency PCM audio streaming. It has proven very efficient, and we are happy to open-source or contribute our C++ implementation to the community as a reference if helpful.
Long-term, maintaining custom WebSocket protocol layers carries maintenance risks. We would love to know if an official, production-ready (GA) C/C++ SDK is on the roadmap to support high-concurrency WebRTC gateways and real-time media servers.
Building a native C++ client on top of Boost.Asio and Boost.Beast to eliminate V8/Python GC pauses on high-concurrency audio streams is awesome engineering, @Martin_Gutschelhofer. When you’re running real-time WebRTC or SIP media gateways at scale, avoiding managed-runtime jitter makes a massive difference in tail latency.
While Google’s officially supported first-party GenAI SDKs (google-genai for Python, @google/genai for TypeScript/Node, Go, and Java) don’t currently include a standalone GA C/C++ distribution, you can make your Boost.BeastBidiGenerateContent layer near-zero maintenance against upstream protocol updates with three patterns we use in native C++20 audio pipelines:
Bind Directly to the Canonical v1beta Protobuf / JSON Schema for the 4 Live Frames: The Gemini Live WebSocket (wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent) only requires four top-level client message envelopes (setup, clientContent, realtimeInput, and toolResponse). Defining those structs with nlohmann::json (NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE) or compiling the official google/ai/generativelanguage/v1beta/generative_service.proto definitions with protoc keeps your wire serialization strictly typed and forward-compatible when new fields are added.
Enable sessionResumption + contextWindowCompression in BidiGenerateContentSetup: To make your C++ WebRTC gateway resilient across long-running streams without dropping audio frames on WebSocket rotation, include both sessionResumption and contextWindowCompression in your initial setup frame:
Whenever the server sends back a sessionResumptionUpdate message with resumable == true, cache newHandle in your C++ session state so Boost.Beast can transparently reconnect with zero context loss.
Open-Sourcing Your Boost.Beast Reference: Please do share the GitHub link if you open-source your C++ client! A clean, header-only Boost.Asio/Boost.Beast transport for 16kHz PCM ingress (audio/pcm;rate=16000) and 24kHz PCM egress would be a huge help to C++, Unreal Engine, and WebRTC developers here on the forum.
Building a native C++ client on top of Boost.Asio and Boost.Beast to eliminate V8/Python GC pauses on high-concurrency audio streams is awesome engineering, @Martin_Gutschelhofer. When you’re running real-time WebRTC or SIP media gateways at scale, avoiding managed-runtime jitter makes a massive difference in tail latency.
While Google’s officially supported first-party GenAI SDKs (google-genai for Python, @google/genai for TypeScript/Node, Go, and Java) don’t currently include a standalone GA C/C++ distribution, you can make your Boost.BeastBidiGenerateContent layer near-zero maintenance against upstream protocol updates with three patterns we use in native C++20 audio pipelines:
Bind Directly to the Canonical v1beta Protobuf / JSON Schema for the 4 Live Frames: The Gemini Live WebSocket (wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent) only requires four top-level client message envelopes (setup, clientContent, realtimeInput, and toolResponse). Defining those structs with nlohmann::json (NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE) or compiling the official google/ai/generativelanguage/v1beta/generative_service.proto definitions with protoc keeps your wire serialization strictly typed and forward-compatible when new fields are added.
Enable sessionResumption + contextWindowCompression in BidiGenerateContentSetup: To make your C++ WebRTC gateway resilient across long-running streams without dropping audio frames on WebSocket rotation, include both sessionResumption and contextWindowCompression in your initial setup frame:
Whenever the server sends back a sessionResumptionUpdate message with resumable == true, cache newHandle in your C++ session state so Boost.Beast can transparently reconnect with zero context loss.
Open-Sourcing Your Boost.Beast Reference: Please do share the GitHub link if you open-source your C++ client! A clean, header-only Boost.Asio/Boost.Beast transport for 16kHz PCM ingress (audio/pcm;rate=16000) and 24kHz PCM egress would be a huge help to C++, Unreal Engine, and WebRTC developers here on the forum.