Bergi のソリューションでは、構造化されたクローン アルゴリズムが audioProcessingEvent の読み取り専用パラメーターをコピーできないという問題が発生します。あなたがする必要があるのは、複製可能なイベントから必要な部分を分割し、次のように別のデータ構造でワーカーに渡すことです。
_onAudioProcess(audioProcessingEvent) {
const {inputBuffer, outputBuffer} = audioProcessingEvent;
// The output buffer contains the samples that will be modified and
// eventually played, so we need to keep a reference to it.
this._outputBuffer = outputBuffer;
const numChannels = inputBuffer.numberOfChannels;
const inputChannels =
Array.from({length: numChannels}, (i) => {
return inputBuffer.getChannelData(i);
});
this._worker.postMessage({
command: 'DO_STUFF',
inputChannels: inputChannels,
});
}
また、処理されたデータをコピーして最終的にユーザーが再生できるようにするには、setMessageHandler の outputBuffer への参照にアクセスする必要があります。