open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

stopMic()#

functionoav-p5
stopMic()

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(), reading micLevel does not turn the microphone back on: that needs startMic() or the 🎤 button.

Examples

jsOpenProcessing ↗
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);
}
Press m to switch the microphone on and off; the circle drops to its smallest size when it is off. Asks for the microphone

Related

  • startMic() Turns the microphone on and returns a promise that says whether it worked.
  • micIsOn Whether the microphone is running right now.
  • micLevel How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).

p5/oav-p5.js, line 1076

↑ Back to top · All names