OAVp5.mic.analyzer#
variableoav-p5OAVp5.mic.analyzer
The AudioAnalyzer from @openav/audio that listens to the microphone, while the microphone is on; null otherwise.
A way into the audio itself when the 0 to 1 numbers are not enough: read the spectrum of the microphone with the browser's own OAVp5.mic.analyzer.analyser.getByteFrequencyData(array), or connect your own Web Audio nodes to it. oav-p5 updates the analyzer once per frame, so do not call its update() yourself.
- Type
AudioAnalyzer | null
Made when the microphone starts and dropped when it stops. It has its own AudioContext (OAVp5.mic.analyzer.ctx) and the Web Audio AnalyserNode it reads from (OAVp5.mic.analyzer.analyser).
Notes
- This is advanced. Check it is not
nullfirst, and read it again afterstopMic()andstartMic(): it is a new object each time.
Examples
let bins;
function setup() {
createCanvas(400, 300);
noStroke();
startMic();
}
function draw() {
background(20);
const a = OAVp5.mic.analyzer;
if (!a) return; // the microphone is not on yet
bins = bins || new Uint8Array(a.analyser.frequencyBinCount);
a.analyser.getByteFrequencyData(bins); // the spectrum, 0..255 per frequency bin
fill(255, 211, 107);
for (let i = 0; i < 64; i++) {
const h = bins[i] / 255 * (height - 20);
rect(20 + i * 5.8, height - 10 - h, 4, h);
}
}Related
OAVp5.mic.start()Turns the microphone on and returns a promise that says whether it worked: the same asstartMic().OAVp5.mic.stateWhere the microphone is:'off','asking','on','denied'or'unavailable'.bassHow much of the microphone's sound is low (bass), middle (mid) or high (treble), each from 0 to 1.micLevelHow loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).