Creating Audio using Javascript in <audio>

后端 未结 2 1241
执念已碎
执念已碎 2021-02-09 09:57

I can\'t find anything through net searches, but is there any plans to make an API to generate audio chunks to be played in an HTML5 tag?

EDIT

2条回答
  •  伪装坚强ぢ
    2021-02-09 10:40

    In theory, you can actually do this now -- set the source attribute of an audio element to a data URI which you build on the fly in your JavaScript. I've done this with embed elements and MIDI files, which works on machines with QuickTime or some other media helper installed.

    The catch, of course, is that generating audio data is a bit more computationally intensive and it takes up more space (which might run afoul of the data URL size limit in certain contexts... IE and Mobile Safari come to mind). So you'd be limited to small clips, and you might be limited by start/stop times for the audio tag.

    Mozilla has an audio buffer API they're working on, which could bring true programatically generated audio to the browser. In the meanwhile, though, it's either Data URI hacks, or plugin-type stuff like Flash (which got a programatic Audio Buffer in version 10) or Java.

    One more note: I started a JavaScript Audio google group a few months back. There isn't a lot of discussion going on there yet, but I'd love it if enough people who were interested in music/audio/sound in the context of the browser signed up so that we can reach a critical mass and start having actual conversations on topics just like this.

提交回复
热议问题