我正试着重拍一些音频。我有一个在Chrome和Firefox中工作的函数,但是它在语句的Edge中崩溃
audioBuffer.copyToChannel(sampleArray,0,0);说copyToChannel没有定义。这很奇怪,因为Microsoft文档专门定义了它:https://dev.windows.com/en-us/microsoft-edge/platform/documentation/apireference/interfaces/audiobuffer/。
不管怎样,我想找个解决办法。在开发人员工具中检查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);
});
}发布于 2019-10-21 13:35:34
我和边缘一起工作:
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();
}https://stackoverflow.com/questions/34814866
复制相似问题