Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(ios): Gemini realtime calls hear you and answer

leepokai6004b22200af
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/GeminiLiveEngine.swift b/apps/ios/Kit/Sources/CodyncUI/Call/GeminiLiveEngine.swift
index b777599f..49c3e066 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/GeminiLiveEngine.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/GeminiLiveEngine.swift
@@ -38,7 +38,8 @@ final class GeminiLiveEngine: VoiceEngine {
private var reconnects = 0
private let engine = AVAudioEngine()
private let player = AVAudioPlayerNode()
- private var audioRunning = false
+ private var audioStarted = false
+ private var configObserver: (any NSObjectProtocol)?
/// Buffers scheduled and not played yet; bumping the generation drops late callbacks.
private var queued = 0
private var playGeneration = 0
@@ -114,12 +115,14 @@ final class GeminiLiveEngine: VoiceEngine {
socket?.cancel(with: .normalClosure, reason: nil)
socket = nil
stopPlayback()
- if audioRunning {
+ if let configObserver { NotificationCenter.default.removeObserver(configObserver) }
+ configObserver = nil
+ if audioStarted {
engine.inputNode.removeTap(onBus: 0)
engine.stop()
- audioRunning = false
+ audioStarted = false
}
- try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
+ try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
}
func interrupt() {
@@ -182,7 +185,7 @@ final class GeminiLiveEngine: VoiceEngine {
if msg["setupComplete"] != nil {
ready = true
reconnects = 0
- if !audioRunning {
+ if !audioStarted {
do {
try startAudio()
} catch {
@@ -250,13 +253,29 @@ final class GeminiLiveEngine: VoiceEngine {
// MARK: audio
private func startAudio() throws {
- let session = AVAudioSession.sharedInstance()
- try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.defaultToSpeaker, .allowBluetoothHFP])
- try session.setActive(true)
- let input = engine.inputNode
- try input.setVoiceProcessingEnabled(true)
+ let session = AVAudioSession.sharedInstance()
+ try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.defaultToSpeaker, .allowBluetoothHFP])
+ try session.setActive(true)
+ try engine.inputNode.setVoiceProcessingEnabled(true)
engine.attach(player)
engine.connect(player, to: engine.mainMixerNode, format: Self.playFormat)
+ // The engine stops itself when it reconfigures (voice processing settling right after the start,
+ // a route change such as AirPods); without a restart the microphone goes quiet.
+ configObserver = NotificationCenter.default.addObserver(forName: .AVAudioEngineConfigurationChange, object: engine,
+ queue: .main) { [weak self] _ in
+ MainActor.assumeIsolated { self?.restartAudio() }
+ }
+ try runAudio()
+ audioStarted = true
+ }
+
+ /// Wires the speaker and taps the microphone for the current hardware, then starts the engine.
+ private func runAudio() throws {
+ // Left implicit, the speaker connection predates voice processing: the engine reconfigures
+ // itself right after starting and stops, and once restarted it still plays nothing.
+ engine.connect(engine.mainMixerNode, to: engine.outputNode, format: nil)
+ let input = engine.inputNode
+ input.removeTap(onBus: 0)
let format = try MicTap.format(of: input)
input.installTap(onBus: 0, bufferSize: 2048, format: format, block: MicTap.pcm16k(from: format) { [weak self] pcm, level in
let audio = pcm.base64EncodedString()
@@ -265,7 +284,16 @@ final class GeminiLiveEngine: VoiceEngine {
engine.prepare()
try engine.start()
player.play()
- audioRunning = true
+ }
+
+ private func restartAudio() {
+ guard audioStarted, !ended, !engine.isRunning else { return }
+ log.info("gemini audio engine reconfigured; restarting")
+ do {
+ try runAudio()
+ } catch {
+ fail("Couldn't use the microphone: \(error.localizedDescription)")
+ }
}
private func captured(_ audio: String, level: Float) {
@@ -306,9 +334,10 @@ final class GeminiLiveEngine: VoiceEngine {
private func stopPlayback() {
playGeneration += 1
queued = 0
- if audioRunning {
+ if audioStarted {
player.stop()
- player.play()
+ // A stopped engine (mid-restart, or failing) would throw; restarting plays the player again.
+ if engine.isRunning { player.play() }
}
}
diff --git a/apps/ios/WhatsNew.md b/apps/ios/WhatsNew.md
index 0fa9ecd2..28d85556 100644
--- a/apps/ios/WhatsNew.md
+++ b/apps/ios/WhatsNew.md
@@ -21,6 +21,7 @@ a version without one gets a generic "Bug fixes and improvements" line. Delete o
- 新增「Open Live Mode」捷徑,選擇 Bot 後直接開啟語音聊天。
- 新增「Send Text to Bot」捷徑,可選擇 Bot 並傳送文字;預設在背景傳送,也可開啟「Open Chat」顯示對話。
- 點對話上方的 Bot 會打開它的詳情、資料庫、記憶與設定;「新會話」改到 Bot 列表的長按選單。
+- 用 Gemini 即時語音通話時,Gemini 聽得到你說話並會回答;先前通話可能一直沒有聲音、也沒有回應。
### en-US
- Bots can make artifacts: reports, trackers and dashboards you come back to show as a card in the chat. Open one full screen and message the bot below it to change it; it updates in place.
@@ -35,6 +36,7 @@ a version without one gets a generic "Bug fixes and improvements" line. Delete o
- Use Open Live Mode in Shortcuts to choose a bot and start voice chat.
- Use Send Text to Bot to choose a bot and send text in the background by default, or enable Open Chat to show the conversation.
- Tapping the bot at the top of its chat opens its Details, Library, Memory and Settings; New session moved to the bot's touch-and-hold menu in the list.
+- Gemini realtime voice calls hear you and answer; before, a call could stay silent with no reply.
## 2.24.0
diff --git a/docs/features/voice-call.md b/docs/features/voice-call.md
index 3bdd9519..a6a54139 100644
--- a/docs/features/voice-call.md
+++ b/docs/features/voice-call.md
@@ -241,6 +241,9 @@ The realtime model is an operator in front of the bot, not a replacement for it
- Gemini connections are replaced before the server's limit: `goAway` closes the socket and the
session resumes on a fresh token with its resumption handle; context window compression lifts the
15-minute audio session cap.
+- On iPhone the Gemini engine wires its speaker output explicitly and restarts its audio engine on
+ `AVAudioEngineConfigurationChange` (voice processing settling right after the start, a route change
+ such as AirPods): the engine stops itself then, and the microphone would stay quiet with no error.
- The chat stays the record: only `send_to_bot` messages and the bot's replies are entries. The
operator's small talk isn't saved; the call still ends with the "Voice chat" notice.
@@ -259,6 +262,12 @@ client secret → `/v1/realtime/calls` SDP → `oai-events` sequence): session u
a spoken reply, and `send_to_bot` called for a Chinese request. The iOS Simulator's voice-processing
audio unit can abort with an RPC timeout when WebRTC starts its audio; use a physical iPhone for audio.
+On 2026-10-25 the iPhone Gemini path (#214) was checked on the iOS Simulator with a real key: speech
+played through the Mac's speakers reached Gemini, which answered aloud and called `send_to_bot`, and
+the bot's reply came back into the chat. The Simulator doesn't cancel echo, so Gemini also hears its own
+voice there; echo cancellation needs a physical iPhone. A physical iPhone and a route change mid-call
+(AirPods) are not checked yet.
+
`StoreTests` cover the operator's tools against a scripted host (send, status with an approval,
option matching, recent messages) and approvals reaching a call as notices. On Android, `VoiceEnginesTest` (core, JVM) drives
each engine through fake audio: utterance cutting and clip playback, OpenAI's event sequence and SDP