Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(events): mic-side capture health states (mic_silent / mic_recovered / mic_capture_failed)

Ezra Ellette54621e13e9ff
diff --git a/crates/screenpipe-events/src/custom_events/audio_health.rs b/crates/screenpipe-events/src/custom_events/audio_health.rs
index 255e40c6e..ed993e90f 100644
--- a/crates/screenpipe-events/src/custom_events/audio_health.rs
+++ b/crates/screenpipe-events/src/custom_events/audio_health.rs
@@ -14,6 +14,14 @@
//!
//! `recovered` is published when speaker audio resumes after a
//! `speaker_silent` was emitted, so subscribers can clear any banner.
+//!
+//! Mic-side states mirror the same pattern for the meeting-input (microphone)
+//! capture path: `mic_silent` is published when the mic is expected to be
+//! capturing (e.g. actively used in a meeting) but no input audio is
+//! reaching the pipeline; `mic_recovered` clears it once input resumes;
+//! `mic_capture_failed` is published when the mic capture path errors out
+//! entirely (e.g. the device is busy or was removed) rather than merely
+//! going silent.
use serde::{Deserialize, Serialize};
@@ -26,10 +34,20 @@ pub enum AudioCaptureHealthState {
SpeakerSilent,
/// Speaker audio resumed after a `SpeakerSilent` event.
Recovered,
+ /// The mic is expected to be capturing, but no input audio has reached
+ /// the capture pipeline.
+ MicSilent,
+ /// Mic input resumed after a `MicSilent` event.
+ MicRecovered,
+ /// The mic capture path failed outright (e.g. device busy or removed),
+ /// rather than merely going silent.
+ MicCaptureFailed,
}
-/// Published as `"audio_capture_health_speaker_silent"` or
-/// `"audio_capture_health_recovered"`. Names are split by state so
+/// Published as `"audio_capture_health_speaker_silent"`,
+/// `"audio_capture_health_recovered"`, `"audio_capture_health_mic_silent"`,
+/// `"audio_capture_health_mic_recovered"`, or
+/// `"audio_capture_health_mic_capture_failed"`. Names are split by state so
/// subscribers can filter without inspecting the payload — same convention
/// as `audio_device_fallback_engaged` / `audio_device_fallback_cleared`.
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -42,6 +60,15 @@ pub struct AudioCaptureHealthEvent {
/// Output devices screenpipe is currently capturing
/// (e.g. `["Speakers (Realtek(R) Audio) (output)"]`).
pub captured_outputs: Vec<String>,
+ /// Input devices screenpipe is currently capturing
+ /// (e.g. `["Rode NT (input)"]`). Mic-side counterpart to
+ /// `captured_outputs`.
+ #[serde(default)]
+ pub capturing_inputs: Vec<String>,
+ /// Human-readable failure reason for `MicCaptureFailed`
+ /// (e.g. `"device busy"`).
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub reason: Option<String>,
}
impl AudioCaptureHealthEvent {
@@ -50,6 +77,8 @@ impl AudioCaptureHealthEvent {
state: AudioCaptureHealthState::SpeakerSilent,
rendering_endpoints,
captured_outputs,
+ capturing_inputs: Vec::new(),
+ reason: None,
}
}
@@ -58,6 +87,38 @@ impl AudioCaptureHealthEvent {
state: AudioCaptureHealthState::Recovered,
rendering_endpoints,
captured_outputs,
+ capturing_inputs: Vec::new(),
+ reason: None,
+ }
+ }
+
+ pub fn mic_silent(capturing_inputs: Vec<String>) -> Self {
+ Self {
+ state: AudioCaptureHealthState::MicSilent,
+ rendering_endpoints: Vec::new(),
+ captured_outputs: Vec::new(),
+ capturing_inputs,
+ reason: None,
+ }
+ }
+
+ pub fn mic_recovered() -> Self {
+ Self {
+ state: AudioCaptureHealthState::MicRecovered,
+ rendering_endpoints: Vec::new(),
+ captured_outputs: Vec::new(),
+ capturing_inputs: Vec::new(),
+ reason: None,
+ }
+ }
+
+ pub fn mic_capture_failed(reason: String) -> Self {
+ Self {
+ state: AudioCaptureHealthState::MicCaptureFailed,
+ rendering_endpoints: Vec::new(),
+ captured_outputs: Vec::new(),
+ capturing_inputs: Vec::new(),
+ reason: Some(reason),
}
}
@@ -66,6 +127,39 @@ impl AudioCaptureHealthEvent {
match self.state {
AudioCaptureHealthState::SpeakerSilent => "audio_capture_health_speaker_silent",
AudioCaptureHealthState::Recovered => "audio_capture_health_recovered",
+ AudioCaptureHealthState::MicSilent => "audio_capture_health_mic_silent",
+ AudioCaptureHealthState::MicRecovered => "audio_capture_health_mic_recovered",
+ AudioCaptureHealthState::MicCaptureFailed => "audio_capture_health_mic_capture_failed",
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn mic_states_have_split_event_names() {
+ assert_eq!(
+ AudioCaptureHealthEvent::mic_silent(vec!["Rode NT (input)".into()]).event_name(),
+ "audio_capture_health_mic_silent"
+ );
+ assert_eq!(
+ AudioCaptureHealthEvent::mic_recovered().event_name(),
+ "audio_capture_health_mic_recovered"
+ );
+ assert_eq!(
+ AudioCaptureHealthEvent::mic_capture_failed("device busy".into()).event_name(),
+ "audio_capture_health_mic_capture_failed"
+ );
+ }
+
+ #[test]
+ fn legacy_speaker_payloads_still_deserialize() {
+ // Additive-field compat: an old payload without the new fields parses.
+ let old = r#"{"state":"speaker_silent","rendering_endpoints":[],"captured_outputs":[]}"#;
+ let ev: AudioCaptureHealthEvent = serde_json::from_str(old).unwrap();
+ assert_eq!(ev.state, AudioCaptureHealthState::SpeakerSilent);
+ assert!(ev.capturing_inputs.is_empty());
+ }
+}