首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Web Audio Api AudioWorklet从音频流中抓取比特并进行BPM检测

使用Web Audio Api AudioWorklet从音频流中抓取比特并进行BPM检测
EN

Stack Overflow用户
提问于 2018-08-18 03:22:01
回答 1查看 1.1K关注 0票数 2

我正在尝试按照cwilso在下面的链接中建议的那样使用AudioWorklet获得块:Using web audio api for analyzing input from microphone (convert MediaStreamSource to BufferSource),但不幸的是我没有让它运行。有人知道如何使用AudioWorker从流中获取数据块,以便进行分析吗?以下是我的代码:

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2018-08-18 03:45:15

根据您需要进行多少处理,您可以在AudioWorkletNode本身中进行处理。

如果不是,则需要使用MessagePort将数据从AudioWorkletNode传递到主线程

您可能还会对MessagePort with AudioWorkletAudioWorklet with SharedArrayBuffer and Worker感兴趣

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51901704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档