hex/src/audio.rs
Dax 492d8c28c4
Labs: voice isolation for dictation on macOS and iOS (#2425) (#2429)
* 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.
2026-11-22 17:00:41 -05:00

78 lines
2.5 KiB
Rust

//! The microphone Hex captures from: the inputs Settings offers, the one
//! stream it keeps open and reopens, and the routes that say when the OS's
//! devices changed.
#[cfg(target_os = "macos")]
pub(crate) mod browser_media;
mod call_input;
mod devices;
mod fixture;
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
pub(crate) mod hex_microphone;
pub(crate) mod idle_sleep;
mod input_format;
pub(crate) mod input_level;
pub(crate) mod instant;
mod interruption;
#[cfg(target_os = "macos")]
mod lid;
pub(crate) mod linger;
#[cfg(any(target_os = "windows", test))]
mod mix_format;
mod open;
pub(crate) mod output_ducking;
pub(crate) mod output_route;
mod overloads;
#[cfg(target_os = "macos")]
pub(crate) mod recording_environment;
mod recovering;
mod recovery;
mod routes;
mod stream;
pub(crate) mod system_idle;
mod transport;
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
pub(crate) mod voice_filter;
#[cfg(target_os = "macos")]
mod voice_processing;
#[cfg(target_os = "windows")]
mod wasapi_capture;
use std::time::Duration;
#[cfg(any(target_os = "linux", target_os = "windows"))]
pub use devices::input_device_names;
pub use devices::{InputDevices, input_devices};
/// A dictation press kept across a microphone reopen (the Linux and Windows
/// listeners read it; macOS has no such reopen).
#[cfg(any(target_os = "linux", target_os = "windows"))]
pub(crate) use interruption::capture_idle;
#[cfg(target_os = "macos")]
pub use open::open_dictation_input;
pub use open::open_meeting_input;
#[cfg(target_os = "macos")]
pub use open::open_named_input;
pub(crate) use open::{LID_CLOSED_ERROR, NO_MICROPHONE_ERROR};
pub use recovering::{RecoveringAudioInput, RecoveringAudioInputEvent};
#[cfg(target_os = "macos")]
pub use routes::notify_audio_service_restarted;
pub use routes::{
audio_service_restart_generation, input_route_generation, output_route_generation,
set_avoid_bluetooth_microphone,
};
pub(crate) use stream::STREAM_STALL_TIMEOUT;
pub use stream::{AudioInput, AudioInputEvent, Opened, Selection};
pub use instant::{CaptureInstant, duration_for_frames};
/// Whether `HEX_AUDIO_FIXTURE` names a WAV file that stands in for every
/// microphone (benchmarks and tests; see `audio/fixture.rs`).
pub fn uses_fixture() -> bool {
fixture::path().is_some()
}
/// How long ago a microphone stream last reported an overload it continued
/// through, for diagnosing captures.
pub fn since_last_stream_glitch() -> Option<Duration> {
overloads::since_last()
}