HTML5网络音频 - 将音频缓冲区转换为wav文件 [英] HTML5 web audio - convert audio buffer into wav file

查看:686
本文介绍了HTML5网络音频 - 将音频缓冲区转换为wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 webkitOfflineAudioContext 来呈现音频缓冲区。现在,我希望将其导出为WAV文件。我该怎么做?我尝试使用recorder.js,但无法弄清楚如何使用它。这是我的代码: http://jsfiddle.net/GBQV8/

I have an audio buffer rendered using webkitOfflineAudioContext. Now, I wish to export it into a WAV file. How do I do it? I tried using recorder.js but couldn't figure out how to use it. Here's my code: http://jsfiddle.net/GBQV8/.

推荐答案

这应该有所帮助:gref =https://gist.github.com/kevincennis/9754325\" rel=\"noreferrer\"> https://gist.github .com / kevincennis / 9754325 。

Here's a gist that should help: https://gist.github.com/kevincennis/9754325.

我没有真正测试过这个,所以可能有一个愚蠢的错字或其他东西,但基本的方法将工作(我以前做过)。

I haven't actually tested this, so there might be a stupid typo or something, but the basic approach will work (I've done it before).

基本上,你将直接使用Recorder.js中的web worker,这样你就可以处理一个大的AudioBuffer了。一次拍摄,而不是实时增量记录。

Essentially, you're going to use the web worker from Recorder.js directly so that you can process one big AudioBuffer all in one shot, rather than recording it incrementally in real-time.

我也会在这里粘贴代码,以防万一有什么事情发生......

I'll paste the code here too, just in case something happens to the gist...

// assuming a var named `buffer` exists and is an AudioBuffer instance


// start a new worker 
// we can't use Recorder directly, since it doesn't support what we're trying to do
var worker = new Worker('recorderWorker.js');

// initialize the new worker
worker.postMessage({
  command: 'init',
  config: {sampleRate: 44100}
});

// callback for `exportWAV`
worker.onmessage = function( e ) {
  var blob = e.data;
  // this is would be your WAV blob
};

// send the channel data from our buffer to the worker
worker.postMessage({
  command: 'record',
  buffer: [
    buffer.getChannelData(0), 
    buffer.getChannelData(1)
  ]
});

// ask the worker for a WAV
worker.postMessage({
  command: 'exportWAV',
  type: 'audio/wav'
});

这篇关于HTML5网络音频 - 将音频缓冲区转换为wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆