5

The Web Audio API seems cool, but I'd really like to use it to processes audio files and then save them as wav files again, and I don't really need to listen to them while they are processing. Is this possible? Is there something like encodeAudioData() to turn the audio buffer back into an ArrayBuffer so I could put it back in a file?

Edit: recorderJS seems almost perfect, but it only outputs 16-bit wavs. Any chance there is something that can do pro-audio formats (24-bit or 32-bit float)?

Rob Allsopp
  • 3,309
  • 5
  • 34
  • 53
  • What exactly is your use case? Sound manipulation is possible though numerous non-JS tools and what your describing sounds like there is no need to use the Web Audio API. If you really want to use it, you probably want to run JS serverside, which means `Node.js`. – Dan Feb 10 '14 at 00:10
  • I'd like to do some leveling based on rms, and also some convolution on wav files. I will only need to do this processing once, but the files will be played back many times. I am running into memory limits with php server-side doing this stuff, so I want to do it client-side. The web audio api can do most of this already, and if I can get the processing back out with relative ease it will do the job nicely. – Rob Allsopp Feb 10 '14 at 00:46
  • Delegating that off to the client does not sound wise to me. For starters, if you do then the client will need to POST the modified sound file back to your server (since you're wanting to do it only one time). If you allow the client to post files back, you have to worry about security. [Check this out for help processing sound in PHP.](http://stackoverflow.com/a/9140566/866618) – Dan Feb 10 '14 at 15:56
  • Take a look at [Recorder.js](https://github.com/mattdiamond/Recorderjs) – MarijnS95 Feb 10 '14 at 19:44
  • possible duplicate of [Offline / Non-Realtime Rendering with the Web Audio API](http://stackoverflow.com/questions/13590999/offline-non-realtime-rendering-with-the-web-audio-api) – Brad Feb 10 '14 at 20:06
  • @Dan, like I said I'm running into server memory limits even with small files. It seems like the only way I could potentially process something like a 3 minute long wav is client-side. Is there some way I can avoid the limits? – Rob Allsopp Feb 10 '14 at 20:08
  • If you're encountering memory issues on your server processing a 3 min WAV then you're doing something wrong. And if your server is dieing processing it, the last thing you want to do is delegate it off to an, on average, substantially less powerful client. – Dan Feb 10 '14 at 21:08
  • Perhaps your PHP memory limit is set too low? Are you getting a PHP error or is your server actually running out of memory? You can change the PHP limit in your php.ini: http://www.php.net/manual/en/ini.core.php#ini.memory-limit – Adrien Delessert Feb 10 '14 at 21:09
  • Hmm I guess a 3 minute, 44.1k, stereo wav is only about 60 MB loaded into memory as floats, and my mem limit is 128M. I suppose I must be doing something wacky. But still, if I want to do any convolution (and I do) I'll need at least 60 more MB available. I'll be rubbing right up against my mem limit all the time. I also have dreams of doing some processing with multiple wav files at a time, so I was just assuming I needed to get off the server to anything like that. – Rob Allsopp Feb 10 '14 at 21:39
  • Did you see [this Stack Overflow answer][1]? [1]: http://stackoverflow.com/questions/8074152/is-there-a-way-to-use-the-web-audio-api-to-sample-audio-faster-than-real-time – Lee Goddard Mar 05 '14 at 18:22
  • There is a [feature request](https://github.com/WebAudio/web-audio-api/issues/496) for encodeAudioData() for the Web Audio API. – Christian d'Heureuse Mar 29 '18 at 18:05

1 Answers1

1

In Web Audio API specification, there is the Offline Context which does exactly what you need.

OfflineAudioContext is a particular type of AudioContext for rendering/mixing-down (potentially) faster than real-time. It does not render to the audio hardware, but instead renders as quickly as possible, calling a completion event handler with the result provided as an AudioBuffer.

zya
  • 830
  • 11
  • 25
  • I looked at this and it gets halfway there for me. I also really want to save the processing I do to a new wav file. It seems I'm going to have to modify recorderJS to output other bit depths or just write my own code for this. – Rob Allsopp Feb 13 '14 at 21:39