open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

micIsOn#

variableoav-p5
micIsOn

Whether the microphone is running right now.

Use it to show a hint until sound arrives: if (!micIsOn) text("Allow the microphone", 20, 30);. Reading it never starts the microphone (unlike micLevel), so it is safe to check anywhere. The reason behind a false is in OAVp5.mic.state (off, asking, on, denied or unavailable) and, when something failed, OAVp5.mic.error.

Type
Boolean

True once the browser has said yes and sound is coming in; false while the microphone is off, still asking, blocked or missing.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function draw() {
  background(micIsOn ? 20 : 90);
  fill(255);
  textAlign(CENTER, CENTER);
  text(micIsOn ? 'listening' : 'allow the microphone', width / 2, height / 2);
}
Grey with a prompt until the microphone is on, then dark. (Nothing here reads micLevel, so nothing asks for the microphone: press 🎤 in the 🎹 panel.)

Related

  • micLevel How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).
  • startMic() Turns the microphone on and returns a promise that says whether it worked.
  • stopMic() Turns the microphone off and sets every microphone value back to 0.

p5/oav-p5.js, line 326

↑ Back to top · All names