Javascript 由于不支持copyToChannel,因此在Microsoft Edge中重新采样音频
我正在尝试对一些音频进行重新采样。我有一个可以在Chrome和Firefox中使用的函数,但是它在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
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用户重新采样的能力。我没有再次访问,看看新版本是否修复了它,但我根据你的问题假设它们没有。