--- url: "https://web.dev/articles/media/microphone-record" titulek: "How to record audio from the user's microphone | Media patterns | web.dev" h1: "How to record audio from the user's microphone Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/media/microphone-record" drobecky: ["Media patterns", "How to record audio from the user's microphone"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:55:35" znaku: 3546 slov: 389 kodovani: "iso-8859-2" sha256: "23845a5c4b912d3a6bcd653203cc49fd5b86cf3e620145a9f72575672c80af27" --- How to record audio from the user's microphone Stay organized with collections Save and categorize content based on your preferences. François Beaufort Accessing the user's camera and microphone is possible on the web platform with the [Media Capture and Streams API](https://www.w3.org/TR/mediacapture-streams/). The [`getUserMedia()`](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia) method prompts the user to access a camera and/or microphone to capture as a media stream. This stream can then be recorded with the [MediaRecorder API](https://developer.chrome.com/blog/mediarecorder) or shared with others over the network. The recording can be saved to a local file via the [`showOpenFilePicker()`](https://developer.mozilla.org/docs/Web/API/Window/showOpenFilePicker) method. The example below shows how you can record audio from the user's microphone in the WebM format and save the recording to the user's file system. `let stream; let recorder; startMicrophoneButton.addEventListener("click", async () => { // Prompt the user to use their microphone. stream = await navigator.mediaDevices.getUserMedia({ audio: true }); recorder = new MediaRecorder(stream); }); stopMicrophoneButton.addEventListener("click", () => { // Stop the stream. stream.getTracks().forEach(track => track.stop()); }); startRecordButton.addEventListener("click", async () => { // For the sake of more legible code, this sample only uses the // `showSaveFilePicker()` method. In production, you need to // cater for browsers that don't support this method, as // outlined in https://web.dev/articles/files/save-a-file/. // Prompt the user to choose where to save the recording file. const suggestedName = "microphone-recording.webm"; const handle = await window.showSaveFilePicker({ suggestedName }); const writable = await handle.createWritable(); // Start recording. recorder.start(); recorder.addEventListener("dataavailable", async (event) => { // Write chunks to the file. await writable.write(event.data); if (recorder.state === "inactive") { // Close the file when the recording stops. await writable.close(); } }); }); stopRecordButton.addEventListener("click", () => { // Stop the recording. recorder.stop(); });` Browser support MediaDevices.getUserMedia() Browser Support 53 12 36 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia) MediaRecorder API Browser Support 47 79 25 14.1 [Source](https://developer.mozilla.org/docs/Web/API/MediaRecorder) File System Access API's showSaveFilePicker() Browser Support 86 86 x x [Source](https://developer.mozilla.org/docs/Web/API/Window/showOpenFilePicker) Further reading [W3C Media Capture and Streams Specification](https://www.w3.org/TR/mediacapture-streams/) [W3C MediaStream Recording Specification](https://w3c.github.io/mediacapture-record/#mediarecorder-api) [WICG File System Access Specification](https://wicg.github.io/file-system-access/) Demo [Open demo](/articles/media/microphone-record/demo) Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2026-09-04 UTC.