stopMic()#
functionoav-p5stopMic()
Turns the microphone off and sets every microphone value back to 0.
It stops the microphone's tracks and closes its audio context, so the browser's "recording" indicator goes away. micLevel, bass, mid, treble and the rest read 0 again, and micIsOn is false.
Returns
Promise<Boolean> Resolves to false, the new state of the microphone.
Notes
- After
stopMic(), readingmicLeveldoes not turn the microphone back on: that needsstartMic()or the 🎤 button.
Examples
function setup() {
createCanvas(400, 300);
textAlign(CENTER, CENTER);
}
function keyPressed() {
if (key === 'm') { if (micIsOn) stopMic(); else startMic(); }
}
function draw() {
background(20);
fill(255);
circle(width / 2, height / 2, 50 + micLevel * 300);
text('press m to turn the microphone ' + (micIsOn ? 'off' : 'on'), width / 2, height - 24);
}Related
startMic()Turns the microphone on and returns a promise that says whether it worked.micIsOnWhether the microphone is running right now.micLevelHow loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).