在 Microsoft Edge 中重新采样音频,因为不支持复制到通道
resampling audio in Microsoft Edge since copyToChannel is not supported
我正在尝试重新采样一些音频。我有一个适用于 Chrome 和 Firefox 的功能,但它在语句的 Edge 中崩溃了
audioBuffer.copyToChannel(sampleArray,0,0);
说没有定义复制到通道。这很奇怪,因为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);
});
}
我在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();
}
相关文章:
- 如何播放部分音频文件
- 音频控件在mouseover上显示,在mouseout上淡出
- HTML5音频加载和播放获胜'我不能在iPad上工作
- onclick函数需要双击,因为类分配延迟
- 是否可以在浏览器中使用纯JavaScript保存音频流
- angular不会更改json的音频源
- 通过幻灯片更改事件停止使用jquery的音频
- 音频和动画在javasctipt循环中同步
- 在ES6中,模块将导致多个网络调用,因为两个模块不能在单个文件中定义
- 使用jQuery控制来自图像的音频
- 如何获得Bootstrap Datepicker的年和月,因为它在变化
- 调整<音频>元素
- ACE编辑器正在删除模块,因为define是't一根绳子
- javascript:发送带有音频文件的POST,然后重定向到新页面
- 使用带有CefSharp或CefGlue的JavaScript的本地或流式音频
- 未能加载,因为找不到支持的源.当播放HTML5音频元素时
- 动态加载的自定义javascript/jQuery/HTML5音频播放器的问题
- 任何人都知道IE7设置或更新/补丁,它可以防止IE因为jquery错误而无法加载页面
- "未捕获类型错误/丢弃意外“;因为一句台词而出现?(HTML w/<脚本>)
- 在 Microsoft Edge 中重新采样音频,因为不支持复制到通道