Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Add AudioEmulator for microphone/getUserMedia testing #12

Description

@noahgift

Problem

Testing real-time audio streaming applications (like whisper.apr) requires mocking navigator.mediaDevices.getUserMedia() to inject controlled audio. Currently this requires ad-hoc JavaScript injection:

// Current approach (demos/tests/src/browser_tests.rs:862)
let mock_media_js = r#"
    navigator.mediaDevices.getUserMedia = async function(constraints) {
        if (constraints.audio) {
            return window.__mockAudioStream;
        }
    };
"#;
page.eval_wasm(mock_media_js).await?;

This violates probar's "ABSOLUTE ZERO JavaScript" principle.

Proposed Solution

Add AudioEmulator to probar::emulation:

pub struct AudioEmulator {
    sample_rate: u32,
    channels: u32,
}

pub enum AudioSource {
    /// Inject WAV file
    WavFile(PathBuf),
    /// Generate sine wave
    SineWave { frequency: f32, duration_ms: u32 },
    /// Generate silence
    Silence { duration_ms: u32 },
    /// Generate speech-like audio (for VAD testing)
    SpeechPattern { pattern: Vec<(f32, u32)> }, // (level, duration_ms)
}

impl AudioEmulator {
    pub fn inject(&self, page: &Page, source: AudioSource) -> ProbarResult<()>;
    pub fn stop(&self, page: &Page) -> ProbarResult<()>;
}

Use Cases

  1. VAD Testing: Inject audio with known speech/silence patterns to verify state transitions
  2. Streaming Tests: Test chunk accumulation and transcription triggering
  3. Performance Tests: Measure RTF (real-time factor) with known audio length
  4. Edge Cases: Test DC offset, clipping, sample rate conversion

Related

  • whisper.apr demo uses streaming transcription that needs this for proper E2E testing
  • Current tests use sine wave oscillator which doesn't trigger VAD properly

Toyota Way

  • Poka-Yoke: Type-safe audio injection prevents format mismatches
  • Muda: Reusable component eliminates ad-hoc JS injection

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions