Skip to content

MediaStream linked to a MediaRecorder without an AudioContext in between results in a runaway recording #404

Open
@CallMeMSL

Description

@CallMeMSL

Hi there,
thank you for your work on this great library!

I want to use this library for a Uni Project where I do live transcription and analyze spoken sentences with an LLM.
Somehow recording the mic doesn't seem to work.
This code produces an 11 Minute .wav file that blasts your ears away with garbage:

fn main() {
    let mic = media_devices::get_user_media_sync(MediaStreamConstraints::Audio);
    let recorder = MediaRecorder::new(&mic);
    let recording: Arc<Mutex<Vec<u8>>> = Default::default();
    let arc = Arc::clone(&recording);
    recorder.set_ondataavailable(move |mut event| {
        let mut r = arc.lock().unwrap();
        r.append(&mut event.blob);
    });
    recorder.start();
    std::thread::sleep(std::time::Duration::from_secs(4));
    recorder.stop();
    std::thread::sleep(std::time::Duration::from_secs(1));
    let data = recording.lock().unwrap();
    let mut file = fs::OpenOptions::new()
        .create(true)
        .write(true)
        .open("unprocessed.wav").unwrap();
    file.write_all(&data).unwrap();
}

Is there something obvious that I am missing? The example for get_user_media_sync for the docs works without any problems and I can hear myself clearly and without any latency.

I am using Linux with PipeWire.

Kind Regards,
David

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions