open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

OAVp5.mic.start()#

functionoav-p5
OAVp5.mic.start()

Turns the microphone on and returns a promise that says whether it worked: the same as startMic().

startMic() is this function: see it for what must happen first (a click, https or localhost). OAVp5.mic.start() also lifts the "stopped by you" mark that stopMic() leaves, which is what lets a later read of micLevel switch the microphone on again.

Returns

Promise<Boolean> Resolves to true once the microphone is on, false if it was blocked, is missing, or the mic option is off.

Examples

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

function mousePressed() {
  OAVp5.mic.start().then((ok) => console.log(ok ? 'microphone on' : 'no microphone'));
}

function draw() {
  background(20);
  fill(255);
  text(OAVp5.mic.state === 'on' ? 'listening' : 'click the canvas to start the microphone', 20, 30);
}
Nothing happens until you click: then the browser asks, and the text changes when the microphone is on. Asks for the microphone

Related

  • startMic() Turns the microphone on and returns a promise that says whether it worked.
  • OAVp5.mic.stop() Turns the microphone off and sets every microphone value back to 0: the same as stopMic().
  • OAVp5.mic.state Where the microphone is: 'off', 'asking', 'on', 'denied' or 'unavailable'.
  • mic Who may turn the microphone on: auto (the first read of micLevel and friends), click (only 🎤 or startMic()) or off (nobody).

p5/oav-p5.js, line 901

↑ Back to top · All names