用 AudioWorklet 替换 scriptProcessorNode [英] Replacing scriptProcessorNode with AudioWorklet

查看:23
本文介绍了用 AudioWorklet 替换 scriptProcessorNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在录制来自用户的麦克风输入并进行处理.问题是我使用 scriptProcessorNode 来处理数据,但是 here 它表示已弃用并替换为 AudioWorklet.问题是没有明确的方法可以用 AudioWorklet 替换此功能,并且从所有 带有来自 Google 的 AudioWorklets 的示例项目,它们都没有对麦克风输入做任何事情.有没有办法用 Audio Worklet 替换此代码?这是应该"替换的代码.

I am working on recording microphone input from the user and processing it. The problem is that I am using scriptProcessorNode to process data, but here it said that is has been deprecated and replaced with AudioWorklet.The problem is that there is no clear way to replace this functionality with AudioWorklet, and from all of the example projects with AudioWorklets from Google, none of them is doing anything with microphone input. Is there a way to replace this code with Audio Worklet? Here is the code that "should" be replaced.

    // Connect analyser
    this.options.source.connect(this.analyser);
    // Create ScriptProcessorNode
    this.scriptProcessorNode = this.options.context.createScriptProcessor(this.options.bufferLen, numChannels, numChannels);
    // Connect scriptProcessorNode (Theretically, not required)
    this.scriptProcessorNode.connect(this.options.context.destination);
    // Create callback to update/analyze floatFrequencyData
    var self = this;
    this.scriptProcessorNode.onaudioprocess = function (event) {
        self.analyser.getFloatFrequencyData(self.floatFrequencyData);
        self.update();
        self.store(event);
        self.monitor();
    };
    // Connect scriptProcessorNode
    this.options.source.connect(this.scriptProcessorNode);

推荐答案

我有一个创建 AudioWorkletProcessor 的简单示例.您可以在此处查看.它仅适用于 Chromium,Firefox 尚不支持 AudioWorklet.

I have a simple example of creating an AudioWorkletProcessor. You can check it here. It only works on Chromium, Firefox don't have support for AudioWorklet yet.

这是我准备显示我遇到的 webpack 错误的示例,因此请仅检查源代码.如果您运行该项目,除非您注释 audio-meter.js 第 8 行并取消注释第 11 行,否则它将失败.文件 audio-meter.worker.js 与相同的内容重复.

It's an example I've prepared to show a webpack error I'm having, so please check only the source code. If you run the project it will fail unless you comment audio-meter.js line 8 and uncomment line 11. The file audio-meter.worker.js is duplicated with the same content.

这篇关于用 AudioWorklet 替换 scriptProcessorNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆