Browser Audio Recorder
Browser Audio Recorder
Build a simple audio recorder that captures the microphone through the browser, displays the signal level, then lets you play back the recording and save it locally.
Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.
Prerequisites
- A modern browser that supports MediaRecorder
- A microphone and permission to use it
- A secure connection (HTTPS or localhost)
Tools
- audio-recorder
- audio-visualizer
Implementation Steps
- Request microphone permission via getUserMedia
- Create a MediaRecorder and attach it to the stream
- Collect data chunks on the ondataavailable event
- Stop recording and create a Blob
- Play the recording with an audio element
- Add a level meter using AnalyserNode
- Allow downloading the file locally without uploading it
Code
let rec, chunks = [];
async function start() {
const stream = await navigator.mediaDevices.getUserMedia({audio: true});
rec = new MediaRecorder(stream);
chunks = [];
rec.ondataavailable = e => chunks.push(e.data);
rec.onstop = () => {
const blob = new Blob(chunks, {type: rec.mimeType});
document.querySelector('audio').src = URL.createObjectURL(blob);
stream.getTracks().forEach(t => t.stop());
};
rec.start();
}
function stop() { rec.stop(); }Expected Results
The browser is expected to record a clip and play it back, and the file format (container and codec) is expected to differ by browser.
These are educational expectations and not experimental results actually measured.
Project Tests
- Record a short sentence and confirm it is audible on playback
- Test denying permission and confirm an understandable message appears
- Open the page in two different browsers and compare the resulting file type
Algorithms
Experiments
Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy
