在< audio>中使用Javascript创建音频 [英] Creating Audio using Javascript in <audio>

查看:158
本文介绍了在< audio>中使用Javascript创建音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过网络搜索找到任何内容,但有没有计划制作一个API来生成音频块,以便在HTML5 < audio> 标签中播放?

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 <audio> tag?

编辑:这是示例::

PSEUDOCODE::
var music = new Song([Array of hertz levels or notes]);
var box = document.createElement('audio');
document.body.appendChild(box);
box.src = music.convert();
box.play();


推荐答案

理论上,你现在可以实际做到这一点 - 将音频元素的source属性设置为您在JavaScript中即时构建的数据URI 。我用嵌入元素和MIDI文件完成了这项工作,这些文件适用于安装了QuickTime或其他媒体助手的机器。

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.

当然,问题在于生成音频数据的计算密集程度更高,并且占用更多空间(在某些情况下可能会违反数据URL大小限制... IE和Mobile Safari会浮现在脑海中)。因此,您只能使用小剪辑,并且您可能会受到 audio 标记的开始/停止时间的限制。

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有一个音频缓冲API 重新开始工作,这可以为浏览器带来真正的编程生成的音频。与此同时,它既可以是数据URI黑客,也可以是插件类型的东西,比如Flash(在版本10中有一个编程音频缓冲区)或Java。

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.

还有一点:我开始 JavaScript几个月前,音频谷歌群组。目前还没有很多讨论,但如果有足够的人对浏览器环境中的音乐/音频/声音感兴趣,那么我就会喜欢它,这样我们才能达到临界质量并开始拥有关于主题的实际对话就像这样。

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.

这篇关于在&lt; audio&gt;中使用Javascript创建音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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