mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-27 07:58:01 +01:00
With Lower audio, Mute, or Pause media, a hotkey capture keeps no pre-roll and asks for output suppression only once it passes the 300 ms hold; Lower audio then ramps over 120 ms on its own thread. Audio still coming from the speakers in that window was counted as speech the stream missed, so nearly every dictation with something playing fell back to the whole clip. The recording environment now reports the moment suppression actually changed the output, and only when it did: Lower audio sends when the ramp first writes its full target, from the ramp's own thread, so a late Bluetooth readback no longer delays it; Mute when the write lands over a non-zero volume; Pause media the latest of the player pause command being issued and the browser pause being sent, without the browser's confirmation windows. The report is asynchronous, so stopping or another session is never held up behind a ramp. Nothing is reported when the effect changed nothing, was skipped on headphones under Labs › Only on speakers, or was stopped before the target was written. The audio owner maps the reported moment onto the recorded timeline and adds a 40 ms speaker-to-microphone margin; up to one resampler input buffer may still be unprocessed, so the position can sit slightly early, which only ever ignores less speech. The live stream's head is raised with Command::IgnoreHead, applied before it finalizes if it arrives before Finish; one after the finish is ignored. Checks: a_reported_effect_raises_the_head_from_the_recorded_timeline, media_speech_before_output_suppression_took_effect_is_not_a_lost_opening, speech_after_the_raised_head_is_still_a_lost_opening, a_head_raised_before_the_finish_keeps_the_stream, a_head_raised_after_the_finish_cannot_save_the_stream, a_guard_reports_when_the_target_is_written_not_when_the_readback_settles, a_guard_that_changes_nothing_reports_no_moment, and muting_an_already_silent_output_changes_nothing. Linux and Windows keep their current head (ROADMAP). Not measured on a microphone or a device.
56 lines
1.8 KiB
Rust
56 lines
1.8 KiB
Rust
//! The macOS recording environment a capture opens for "While dictating":
|
|
//! idle-sleep prevention, output suppression, paused media, and the moments
|
|
//! suppression says it actually took effect.
|
|
use std::sync::mpsc;
|
|
|
|
use crate::audio::CaptureInstant;
|
|
use crate::audio::recording_environment::{
|
|
RecordingEnvironmentController, RecordingEnvironmentSession,
|
|
};
|
|
|
|
use super::Recording;
|
|
|
|
pub(super) enum RecordingEnvironmentState {
|
|
Disabled,
|
|
Pending(RecordingEnvironmentController),
|
|
Active {
|
|
_session: RecordingEnvironmentSession,
|
|
},
|
|
}
|
|
|
|
impl RecordingEnvironmentState {
|
|
/// Starts the environment now and keeps its report channel, so output
|
|
/// suppression can say when it actually took effect.
|
|
pub(super) fn activate(&mut self, reports: &mut Option<mpsc::Receiver<CaptureInstant>>) {
|
|
let Self::Pending(controller) = self else {
|
|
return;
|
|
};
|
|
let controller = controller.clone();
|
|
let (report, receiver) = mpsc::channel();
|
|
*reports = Some(receiver);
|
|
*self = Self::Active {
|
|
_session: controller.begin_reporting(report),
|
|
};
|
|
}
|
|
}
|
|
|
|
impl Recording {
|
|
/// Raises the head to where output suppression actually took effect, as
|
|
/// the environment reported it, and tells an open stream.
|
|
pub(super) fn apply_suppression_report(&mut self) {
|
|
let Some(at) = self.effective_suppression() else {
|
|
return;
|
|
};
|
|
let Some(head) = self.note_suppression_through(at) else {
|
|
return;
|
|
};
|
|
if let Some(stream) = &mut self.stream {
|
|
stream.raise_ignored_head(head);
|
|
}
|
|
}
|
|
|
|
/// The latest moment "While dictating" actually changed the environment.
|
|
fn effective_suppression(&mut self) -> Option<CaptureInstant> {
|
|
self.suppression_reports.as_mut()?.try_iter().last()
|
|
}
|
|
}
|