mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +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.
85 lines
3.7 KiB
Swift
85 lines
3.7 KiB
Swift
import SwiftUI
|
||
import UIKit
|
||
|
||
@main
|
||
struct HEXMobileApp: App {
|
||
@Environment(\.scenePhase) private var scenePhase
|
||
@State private var dictation = DictationController.shared
|
||
@State private var openedFromKeyboard = Self.initialOpenedFromKeyboard
|
||
@State private var showSetup = SettingsSnapshotFixture.showsSetupSheet
|
||
@State private var openPage: SettingsPage?
|
||
|
||
init() {
|
||
FullKeyboardSettings().applyLaunchArguments()
|
||
TypingLogSettings().turnOffOnce()
|
||
TypingLogSettings().applyLaunchArguments()
|
||
HinglishSettings().applyLaunchArguments()
|
||
GreeklishSettings().applyLaunchArguments()
|
||
TwoLanguageDictationSettings().applyLaunchArguments()
|
||
VoiceIsolationSettings().applyLaunchArguments()
|
||
MultilingualParakeetSettings().applyLaunchArguments()
|
||
KeyboardParakeetSettings().applyLaunchArguments()
|
||
SettingsSnapshotFixture.applyDefaults()
|
||
}
|
||
|
||
private static var initialOpenedFromKeyboard: Bool {
|
||
let args = ProcessInfo.processInfo.arguments
|
||
guard let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count else {
|
||
return false
|
||
}
|
||
return args[idx + 1].hasPrefix("handoff-")
|
||
}
|
||
|
||
var body: some Scene {
|
||
WindowGroup {
|
||
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil {
|
||
Color.clear
|
||
} else if let keyboardScene = KeyboardSnapshotStage.requestedScene {
|
||
KeyboardSnapshotStage(scene: keyboardScene)
|
||
} else if let fullKeyboardScene = FullKeyboardSnapshotStage.requestedScene {
|
||
FullKeyboardSnapshotStage(scene: fullKeyboardScene)
|
||
} else if let experimentsScene = ExperimentsSnapshotStage.requestedScene {
|
||
ExperimentsSnapshotStage(scene: experimentsScene)
|
||
} else if let hostedScene = HostedKeyboardConversationStage.requestedScene {
|
||
HostedKeyboardConversationStage(scene: hostedScene, dictation: dictation)
|
||
} else {
|
||
ContentView(
|
||
dictation: dictation,
|
||
openedFromKeyboard: $openedFromKeyboard,
|
||
showSetup: $showSetup,
|
||
openPage: $openPage
|
||
)
|
||
.onOpenURL { url in
|
||
guard let request = KeyboardLaunchRequest(url: url) else { return }
|
||
if case .setup = request {
|
||
openedFromKeyboard = false
|
||
showSetup = true
|
||
} else if case .translationSettings = request {
|
||
openedFromKeyboard = false
|
||
openPage = .dictation
|
||
} else if case .pasteSettings = request {
|
||
openedFromKeyboard = false
|
||
openPage = .keyboard
|
||
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
|
||
UIApplication.shared.open(settingsURL)
|
||
}
|
||
} else {
|
||
openedFromKeyboard = true
|
||
}
|
||
dictation.handleKeyboardLaunch(request)
|
||
}
|
||
.onChange(of: scenePhase) { _, phase in
|
||
if phase == .background {
|
||
openedFromKeyboard = false
|
||
dictation.appMovedToBackground()
|
||
} else if phase == .active {
|
||
dictation.endStaleLiveActivities()
|
||
dictation.appBecameActive()
|
||
// Experiments › Speech model in keyboard: picks its download up.
|
||
dictation.startKeyboardParakeetDownloadIfWanted()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|