admin管理员组文章数量:1425791
I made changes to an audio buffer like gain and panning, connected them to an audio context. Now I want to save to a file with all the implemented changes. Saving the buffer as is would give me the original audio without the changes.
Any idea of a method or a procedure existed to do that?
I made changes to an audio buffer like gain and panning, connected them to an audio context. Now I want to save to a file with all the implemented changes. Saving the buffer as is would give me the original audio without the changes.
Any idea of a method or a procedure existed to do that?
Share Improve this question asked Mar 22, 2021 at 1:46 ShemShem 4184 silver badges8 bronze badges 1- making changes to buffer as you say is very similar to connecting the audio context to a file sink after running it thru an encoder, see the example saving encoded web audio to a file : github./GersonRosales/… – Robert Rowntree Commented Mar 22, 2021 at 15:22
2 Answers
Reset to default 3On way is to use a MediaRecorder
to save the modified audio.
So, in addition to connecting to the destination, connect to a MediaStreamDestinationNode
. This node has a stream object that you can use to initialize a MediaRecorder
. Set up the recorder to save the data when data is available. When you're down recording, you have a blob that you can then download.
Many details are missing here, but you can find out how to use a MediaRecorder using the MDN example.
I found a solution, with OfflineAudioContext. Here is an example with adding a gain change to my audio and saving it. On the last line of the code I get the array buffer with the changes I made. From there, I can go on saving the file.
let offlineCtx = new OfflineAudioContext(this.bufferNode.buffer.numberOfChannels, this.bufferNode.buffer.length, this.bufferNode.buffer.sampleRate);
let obs = offlineCtx.createBufferSource();
obs.buffer = this.buffer;
let gain = offlineCtx.createGain();
gain.gain.value = this.gain.gain.value;
obs.connect(gain).connect(offlineCtx.destination);
obs.start();
let obsRES = this.ctx.createBufferSource();
await offlineCtx.startRendering().then(r => {
obsRES.buffer = r;
});
本文标签: javascriptWeb Audio APIHow do I save the audio buffer to a file including all changesStack Overflow
版权声明:本文标题:javascript - Web Audio API - How do I save the audio buffer to a file including all changes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745394660a2656758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论