Javascript 使用Web Audio Api AudioWorklet从audiostream获取位并执行BPM检测

Javascript 使用Web Audio Api AudioWorklet从audiostream获取位并执行BPM检测,javascript,audio-recording,web-audio-api,Javascript,Audio Recording,Web Audio Api,我正在尝试使用AudioWorklet获取块,就像cwilso在以下链接中建议的那样:,但不幸的是,我没有让它运行。有人知道吗,我是如何从音频工作者的流中获取块的,这样我就可以分析它们了?这是我的密码: navigator.mediaDevices.getUserMedia({ audio: true, video: false }) .then(function(stream) { /* use the stream */ var audioCtx = new (window.

我正在尝试使用AudioWorklet获取块,就像cwilso在以下链接中建议的那样:,但不幸的是,我没有让它运行。有人知道吗,我是如何从音频工作者的流中获取块的,这样我就可以分析它们了?这是我的密码:

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(function(stream) {
    /* use the stream */
    var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // define audio context
    var source = audioCtx.createMediaStreamSource(stream);
    //connect stream to a web audio context with a MediaStreamAudioNode
    source.connect(audioCtx);
    //Use an AudioWorklet to grab the bits and do detection
    //https://developers.google.com/web/updates/2017/12/audio-worklet
    //https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern
    //https://webaudio.github.io/web-audio-api/#audioworklet
    audioCtx.audioWorklet.addModule('AudioWorklet.js').then(() => {
      let bypassNode = new AudioWorkletNode(audioCtx, 'bypass-processor');
    });

    //collect chunks for beat detection

    //do BPM detection

})
.catch(function(err) {
    /* handle the error */
    alert("Error");
});
        // Script in an extra file like it is explained in the api
class BypassProcessor extends AudioWorkletProcessor {
process (inputs, outputs) {
// Single input, single channel.
let input = inputs[0];
let output = outputs[0];
output[0].set(input[0]);
// Process only while there are inputs.
alert(input);
alert(output);
return false;}}); registerProcessor('bypass-processor', BypassProcessor);

根据需要执行的处理量,您可以在
AudioWorkletNode
本身中执行

如果没有,则需要使用


您可能还对和感兴趣,这取决于您需要执行的处理量,您可以在
AudioWorkletNode
本身中执行

如果没有,则需要使用


您可能还对音频流感兴趣,我想处理30秒的音频流。我需要在我的代码中修改什么才能实现这一点?我想处理30秒的音频流。为了实现这一点,我需要在代码中修改什么?