- From: Olli Pettay <Olli.Pettay@helsinki.fi>
- Date: Thu, 03 Mar 2011 17:02:22 +0200
- To: Jussi Kalliokoski <jussi.kalliokoski@gmail.com>
- CC: public-xg-audio@w3.org
On 03/03/2011 04:43 PM, Jussi Kalliokoski wrote: > Hello all! > > A thought came in to my mind just now: canvas API provides means to > convert images from png to jpg, or just save the results created by > programmatic drawing, why don't <audio> and <video> have these > capabilities? I mean, implementing this behavior is not a big deal and > thus could be standardized pretty quickly. After all, the browsers > *already* have the codecs implemented in one way or another, why > shouldn't they be made available via APIs as well? > > Imagine this: > > var myAudio = new Audio('whatever.wav'); > // Would return a string for the wav file converted to ogg, in binary > form, like it would have been read from a file. > myAudio.toData('audio/ogg'); > > myAudio = new Audio('something.ogg'); > // The same, except vice versa, thus allowing us to go through the raw > data hidden underneath the binary nonsense. > myAudio.toData('audio/wav'); > > // This would be just a stupid thing to do, unless the content was > generated, but who knows if someone would find use for this. Same could > also be achieved by doing btoa() conversion to the .toData() output. > myAudio.toDataUrl('audio/mp3'); > > // Also, pretty much useless, if performance is not regarded, we could > just create new Audio(header + btoa()); > myAudio = Audio.fromData(data, 'audio/ogg'); > > Very simple, yes? Not hard to implement, like I said, the encoders / > decoders are already there. Decoders are there, but I doubt encoders. > Useful? Very. For example, let's say we > wanted to record data that's generated by our Audio demos/apps, then we > wanted it to be stored on the users computer via say, File API? We very > much would like it to be compressed, but not as much as the end user does. I guess .wav could be supported easily. .ogg perhaps in some browsers, but support for .mp3 would be trickier because of licensing and patents. Also, encoding can take a lot of time so the method should work asynchronously. Btw, since <audio> is defined in HTML, and this feature isn't exactly about creating/modifying audio data, this discussion should probably go to WhatWG. -Olli
Received on Thursday, 3 March 2011 15:52:26 UTC