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): calls leave the audio system alone until they use it

leepokaided858ed5455
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/CallAudio.swift b/apps/ios/Kit/Sources/CodyncUI/Call/CallAudio.swift
index c3993559..22a6441c 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/CallAudio.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/CallAudio.swift
@@ -36,15 +36,22 @@ enum CallAudioSession {
/// The category options of every engine's audio, WebRTC's too.
static let options: AVAudioSession.CategoryOptions = [.defaultToSpeaker, .allowBluetoothHFP]
+ /// The session was activated and not released since: releasing an untouched one would start the audio system
+ /// for nothing (in tests that start CoreAudio, which can deadlock on a simulator).
+ private static var active = false
+
/// Before an engine's audio starts or resumes.
static func activate() throws {
let session = AVAudioSession.sharedInstance()
try session.setCategory(.playAndRecord, mode: .voiceChat, options: options)
try session.setActive(true)
+ active = true
}
/// After an engine stops.
static func release() {
+ guard active else { return }
+ active = false
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
}
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/CloudSpeechEngine.swift b/apps/ios/Kit/Sources/CodyncUI/Call/CloudSpeechEngine.swift
index 0ce9ea83..1e2fb15a 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/CloudSpeechEngine.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/CloudSpeechEngine.swift
@@ -33,7 +33,8 @@ final class CloudSpeechEngine: VoiceEngine {
private let speech: Speech
private let chunk: Int
- private let engine = AVAudioEngine()
+ /// Created when the microphone first opens: touching the audio system starts it.
+ @ObservationIgnored private lazy var engine = AVAudioEngine()
private var audioRunning = false
private var ended = false
private var events: AudioSessionEvents?
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/OnDeviceEngine.swift b/apps/ios/Kit/Sources/CodyncUI/Call/OnDeviceEngine.swift
index d9f38969..c96fa647 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/OnDeviceEngine.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/OnDeviceEngine.swift
@@ -35,7 +35,10 @@ final class OnDeviceEngine: VoiceEngine {
/// The language picked in the call settings, else the phone's.
private let recognizer = UserDefaults.standard.string(forKey: OnDeviceEngine.languageKey)
.flatMap { $0.isEmpty ? nil : SFSpeechRecognizer(locale: Locale(identifier: $0)) } ?? SFSpeechRecognizer()
- private let engine = AVAudioEngine()
+ /// Created when the microphone first opens: touching the audio system starts it.
+ @ObservationIgnored private lazy var engine = AVAudioEngine()
+ /// The microphone tap is on.
+ private var tapped = false
private var request: SFSpeechAudioBufferRecognitionRequest?
private var task: SFSpeechRecognitionTask?
/// Bumped per utterance so late callbacks from a cancelled recognition are dropped.
@@ -177,6 +180,7 @@ final class OnDeviceEngine: VoiceEngine {
input.installTap(onBus: 0, bufferSize: 1024, format: format, block: Self.tap(request) { [weak self] level in
Task { @MainActor in self?.level = level }
})
+ tapped = true
engine.prepare()
try engine.start()
} catch {
@@ -194,8 +198,11 @@ final class OnDeviceEngine: VoiceEngine {
task = nil
request?.endAudio()
request = nil
- if engine.isRunning { engine.stop() }
- engine.inputNode.removeTap(onBus: 0)
+ if tapped {
+ if engine.isRunning { engine.stop() }
+ engine.inputNode.removeTap(onBus: 0)
+ tapped = false
+ }
level = 0
}