---
url: "https://web.dev/articles/media/microphone-process/pattern"
titulek: "web.dev"
h1: ""
popis: ""
jazyk: "en"
kanonicka: "https://web.dev/articles/media/microphone-process/pattern"
drobecky: []
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-14 01:47:12"
znaku: 2507
slov: 293
kodovani: "iso-8859-2"
sha256: "a8a8459ef340ca3c3ee2afb970bddf781f1351db633697aa6277aa5fb1a8e283"
---
Stay organized with collections
Save and categorize content based on your preferences.
HTML `
How to process audio from the user's microphone
How to process audio from the user's microphone
` CSS `:root { color-scheme: dark light; } html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } body { margin: 1rem; font-family: system-ui, sans-serif; } button { display: block; margin-bottom: 4px; } pre { color: red; white-space: pre-line; }` JS `const startMicrophoneButton = document.querySelector('#startMicrophoneButton'); const stopMicrophoneButton = document.querySelector('#stopMicrophoneButton'); let stream; startMicrophoneButton.addEventListener("click", async () => { // Prompt the user to use their microphone. stream = await navigator.mediaDevices.getUserMedia({ audio: true, }); const context = new AudioContext(); const source = context.createMediaStreamSource(stream); // Load and execute the module script. await context.audioWorklet.addModule("processor.js"); // Create an AudioWorkletNode. The name of the processor is the // one passed to registerProcessor() in the module script. const processor = new AudioWorkletNode(context, "processor"); source.connect(processor).connect(context.destination); stopMicrophoneButton.disabled = false; log("Your microphone audio is being used."); }); stopMicrophoneButton.addEventListener("click", () => { // Stop the stream. stream.getTracks().forEach(track => track.stop()); log("Your microphone audio is not used anymore."); });` 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-07-29 UTC.