ScriptProcessorNode 已弃用。使用 AudioWorkletNode 代替

4 audio

网站上有录音机和录音播放器。在 Firefox 中没问题,但在基于 Chronium 的浏览器中我收到以下警告。

[弃用] ScriptProcessorNode 已弃用。请改用 AudioWorkletNode。(https://developers.google.com/web/updates/2017/12/audio-worklet

this.config = {
                        bufferLen: 4096,
                        numChannels: 2,
                        mimeType: 'audio/ogg'
                    };
                    this.recording = false;
                    this.callbacks = {
                        getBuffer: [],
                        exportWAV: []
                    };
                    Object.assign(this.config, cfg);
                    this.context = source.context;
                    this.node = (this.context.createScriptProcessor || this.context.createJavaScriptNode).call(this.context, this.config.bufferLen, this.config.numChannels, this.config.numChannels);
                    this.node.onaudioprocess = function (e) {
                        if (!_this.recording) return;
                        var buffer = [];
                        for (var channel = 0; channel < _this.config.numChannels; channel++) {
                            buffer.push(e.inputBuffer.getChannelData(channel));
                        }
                        _this.worker.postMessage({
                            command: 'record',
                            buffer: buffer
                        });
                    };
Run Code Online (Sandbox Code Playgroud)

PasteBin 上的完整代码

在此输入图像描述

我怎样才能做出这个改变?

Bra*_*rad 5

ScriptProcessorNode 已被“弃用”多年,但短期内不会消失。

但是,如果您想要在 Ogg 中录制 Vorbis 或 Opus 音频,则无论如何都不需要它。请改用 MediaRecorder API。 https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder