mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-27 07:58:01 +01:00
* Labs: voice isolation for dictation on macOS and iOS (#2425) * voice isolation: harden the macOS bridge and keep the fallback raw Adds an NSLock gate around the tap and configuration observer with a clean teardown, an Objective-C @try/@catch guard for AVAudioEngine exceptions, format and device verification, a channel-0 Float32 tap, configuration-change reporting, and a remembered raw fallback per microphone. Fixes the iOS category comparison for voiceChat's implicit hands-free Bluetooth and rewords the experiment's copy. * voice isolation: reopen on engine reconfiguration without falling back Reports an AVAudioEngineConfigurationChange only after start, and only while the engine has stopped, as its own reopen marker so RecoveringAudioInput does not remember it as a voice-processing failure; more than three reopens in 30 s still fall back to the raw stream. Forgets a remembered fallback when the resolved device changes, reports both AudioDeviceIDs on a device mismatch, fixes the bridge comments, and documents Bluetooth call-profile and configuration-change behavior on macOS and iOS. * voice isolation: fix the Windows open-by-name call open_matching still passed five arguments to open_device after voice_processing_fallback was added, which only Windows compiles, so the Windows clippy job failed. It opens by name without voice processing, so both voice-processing arguments stay false.
29 lines
1.2 KiB
Swift
29 lines
1.2 KiB
Swift
import Foundation
|
||
|
||
/// Experiments › Voice isolation, in the shared App Group so in-keyboard dictation
|
||
/// reads it too. Off by default. While it is on, the app records in
|
||
/// `AVAudioSession.Mode.voiceChat` instead of `.measurement`, so Control Center's Mic Mode
|
||
/// can offer Voice Isolation while Hex records, and in-keyboard dictation asks WebKit for
|
||
/// echo cancellation and noise suppression. Off, both record exactly as before.
|
||
nonisolated struct VoiceIsolationSettings {
|
||
static let enabledKey = "experiments.voiceIsolation"
|
||
static let launchArgument = "--experiment-voice-isolation"
|
||
|
||
private let defaults: UserDefaults?
|
||
|
||
init(defaults: UserDefaults? = UserDefaults(suiteName: KeyboardBridge.appGroup)) {
|
||
self.defaults = defaults
|
||
}
|
||
|
||
var isEnabled: Bool {
|
||
get { defaults?.bool(forKey: Self.enabledKey) ?? false }
|
||
nonmutating set { defaults?.set(newValue, forKey: Self.enabledKey) }
|
||
}
|
||
|
||
/// Simulator scenes pass `--experiment-voice-isolation` to turn the experiment on.
|
||
func applyLaunchArguments(_ arguments: [String] = ProcessInfo.processInfo.arguments) {
|
||
if arguments.contains(Self.launchArgument) {
|
||
isEnabled = true
|
||
}
|
||
}
|
||
}
|