是否可以使用 JavaScript 在浏览器中播放合成声音?

发布于 2024-08-09 14:43:40 字数 276 浏览 2 评论 0原文

我刚刚在互联网上发现了一个 完全用 JavaScript 编写的任天堂模拟器,但它没有声音。这让我开始思考:有没有办法使用 JavaScript 在浏览器中合成声音然后播放?如果一般情况下不可能,那么是否有 Safari/Opera/FireFox/IE/Etc。使之成为可能的扩展?

我不是在询问合成声音的技术,只是询问播放由浏览器中运行的代码合成的声音的技术。

I just came across a Nintendo emulator written entirely in JavaScript on the interwebs, but it doesn't have sound. It got me thinking: Is there any way to synthesize sound in the browser using JavaScript and then play it? If it's not possible in general, then are there any Safari/Opera/FireFox/IE/Etc. extensions that would make it possible?

I am not asking about techniques for synthesizing sound, just techniques for playing sounds that have been synthesized by code running in the browser.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

↙温凉少女 2024-08-16 14:43:40

我想你最好的选择是让 Javascript 使用ExternalInterface (http: //www.adobe.com/devnet/flash/articles/external_interface.html)。 Flash 现在有一种在声音缓冲区和通用 ByteArray 类之间传输数据的方法。

http://www.adobe.com/devnet/flash/articles/dynamic_sound_ Generation/< /a>

您可以使用 Flex SDK 免费开发 Flash http://www.adobe.com/产品/柔性/

I would imagine your best bet is to have Javascript talk to Flash using ExternalInterface (http://www.adobe.com/devnet/flash/articles/external_interface.html). Flash now has a way of transfering data between the sound buffers and a general purpose ByteArray classs.

http://www.adobe.com/devnet/flash/articles/dynamic_sound_generation/

You can develop Flash for free using the Flex SDK http://www.adobe.com/products/flex/.

雨的味道风的声音 2024-08-16 14:43:40

大多数开发人员想要使用 JavaScript 添加声音到应用程序时,都会使用 SoundManager 2。它具有挂钩,因此 JavaScript 可以与 Flash 8 和 9 功能进行交互。我不确定它是否暴露了使用字节数据的能力,我猜你正在追求这一点,我从来没有处理过这个问题。

Most developers use SoundManager 2 when they want to add sound to their application with JavaScript. It has hooks so JavaScript can interact with Flash 8 and 9 features. I am not sure if it has exposed the ability to work with Byte Data which I guess you are after, I never had to deal with that.

伴我心暖 2024-08-16 14:43:40

原来NES模拟器的作者找到了一个动态音频库:

https://github.com/bfirsh /dynamicaudio.js

我还没有尝试过,但文档看起来很有希望:

var DynamicAudio = new DynamicAudio({'swf':
'/static/dynamicaudio.swf'})

写(样本); // 播放 -1.0 到范围内的浮点音频样本数组
1.0。

It turns out the author of the NES emulator has found a dynamic audio library:

https://github.com/bfirsh/dynamicaudio.js

I haven't tried it, but the docs look promising:

var dynamicaudio = new DynamicAudio({'swf':
'/static/dynamicaudio.swf'})

write(samples); // Plays an array of floating point audio samples in the range -1.0 to
1.0.

稚然 2024-08-16 14:43:40

理论上,应该可以合成声音,然后让浏览器使用数据 URL 来播放它们。

在实践中,Steven Wittens 实际上制作了一个演示技术。 encodeAudio8bitencodeAudio16bit 函数是神奇发生的地方。

In theory it should be possible to synthesize the sounds and then get the browser to play them using a data URL.

In practice, Steven Wittens has actually produced a demo of this technique. The encodeAudio8bit and encodeAudio16bit functions are where the magic happens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文