海信医疗-远程超声管理平台-信创国产化
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
832 B

5 days ago
class AudioLevelProcessor extends AudioWorkletProcessor {
constructor() {
super();
this._lastUpdate = currentTime;
}
process(inputs, outputs, parameters) {
if (!inputs) {
return;
}
if (currentTime - this._lastUpdate >= 0.1) {
if (!inputs[0] || !inputs[0][0]) {
//console.log('@@');
return;
}
//auconsole.log('@@',inputs[0][0]);
const buffer = inputs[0][0];
let max = Math.floor(Math.max.apply(Math, buffer) * 100);
if (max < 0) {
max = -max;
}
this.port.postMessage({audioLevel: max});
this._lastUpdate = currentTime;
}
return true;
}
}
registerProcessor('audioLevel', AudioLevelProcessor);