Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 由于不支持copyToChannel,因此在Microsoft Edge中重新采样音频_Javascript_Html5 Audio_Microsoft Edge - Fatal编程技术网

Javascript 由于不支持copyToChannel,因此在Microsoft Edge中重新采样音频

Javascript 由于不支持copyToChannel,因此在Microsoft Edge中重新采样音频,javascript,html5-audio,microsoft-edge,Javascript,Html5 Audio,Microsoft Edge,我正在尝试对一些音频进行重新采样。我有一个可以在Chrome和Firefox中使用的函数,但是它在Edge的声明中崩溃了 audioBuffer.copyToChannel(sampleArray,0,0); 说copyToChannel没有定义。这很奇怪,因为Microsoft文档专门定义了它: 不管怎样,我正在寻找解决办法。在开发工具中检查audioBuffer对象并没有给我任何线索 谢谢 这是我的密码: function reSample(sampleArray, targetSampl

我正在尝试对一些音频进行重新采样。我有一个可以在Chrome和Firefox中使用的函数,但是它在Edge的声明中崩溃了

audioBuffer.copyToChannel(sampleArray,0,0);
说copyToChannel没有定义。这很奇怪,因为Microsoft文档专门定义了它:

不管怎样,我正在寻找解决办法。在开发工具中检查audioBuffer对象并没有给我任何线索

谢谢

这是我的密码:

function reSample(sampleArray, targetSampleRate, onComplete) {
    // sampleArray is a Float32Array
    // targetSampleRate is an int (22050 in this case)
    // onComplete is called with the new buffer when the operation is complete
    var audioCtx = new window.AudioContext();

    var audioBuffer = audioCtx.createBuffer(1, sampleArray.length, audioCtx.sampleRate);
    audioBuffer.copyToChannel(sampleArray,0,0); // Not supported by Microsoft Edge 12, evidently.

    var channel = audioBuffer.numberOfChannels;
    var samples = audioBuffer.length * targetSampleRate / audioBuffer.sampleRate;

    var offlineContext = new window.OfflineAudioContext(channel, samples, targetSampleRate);
    var bufferSource = offlineContext.createBufferSource();
    bufferSource.buffer = audioBuffer;

    bufferSource.connect(offlineContext.destination);
    bufferSource.start(0);
    offlineContext.startRendering().then(function(renderedBuffer){
        onComplete(renderedBuffer);
    });
}

我用Edge做了这个:

    const offlineCtx = new OfflineAudioContext(sourceBuffer.numberOfChannels, sourceBuffer.duration *
      this.sampleRate, this.sampleRate);
    const cloneBuffer = offlineCtx.createBuffer(sourceBuffer.numberOfChannels, sourceBuffer.length, sourceBuffer.sampleRate);
    cloneBuffer.copyToChannel(sourceBuffer.getChannelData(0), 0);
    const source = offlineCtx.createBufferSource();
    source.buffer = cloneBuffer;
    offlineCtx.oncomplete = (e) => {
      const left = e.renderedBuffer.getChannelData(0);
      this.onAudioProcess(this.float32ToInt16(left, left.length), e.renderedBuffer.duration * 1000);
    };
    source.connect(offlineCtx.destination);
    source.start(0);
    offlineCtx.startRendering();
  }

你找到解决方案了吗?我没有-我只是没有给Edge用户重新采样的能力。我没有再次访问,看看新版本是否修复了它,但我根据你的问题假设它们没有。