如何编写基于网络的音乐可视化工具?
我正在尝试找到构建音乐可视化工具以在网络浏览器中运行的最佳方法。 Unity 是一个选项,但我需要构建一个自定义音频导入/分析插件来获取最终用户的声音输出。 Quartz 可以满足我的需要,但只能在 Mac/Safari 上运行。 WebGL 似乎还没有准备好。 Raphael 主要是 2D,并且仍然存在获取用户声音的问题......有什么想法吗?以前有人这样做过吗?
I'm trying to find the best approach to build a music visualizer to run in a browser over the web. Unity is an option, but I'll need to build a custom audio import/analysis plugin to get the end user's sound output. Quartz does what I need but only runs on Mac/Safari. WebGL seems not ready. Raphael is mainly 2D, and there's still the issue of getting the user's sound... any ideas? Has anyone done this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
让音频响应起来非常简单。 这是一个开源网站,其中包含大量音频反应示例。
至于如何做到这一点,您基本上使用 Web Audio API 来传输音乐并使用其 AnalyserNode 来获取音频数据。
然后就由你来画一些有创意的东西了。
请注意您可能会遇到的一些麻烦。
目前(2017/1/3)Android Chrome 和 iOS Safari 均不支持分析流式音频数据。相反,您必须加载整首歌曲。 这是一个试图稍微抽象一下的库
在移动设备上您无法自动播放音频。您必须根据用户输入(例如'click'
或'touchstart'
)在输入事件内启动音频。正如示例中所指出的,只有当源来自同一域或者您请求 CORS 权限并且服务器授予权限时,您才能分析音频。据我所知,只有 Soundcloud 给予许可,并且是按每首歌为基础的。是否允许对特定歌曲进行音频分析取决于各个艺术家的歌曲设置。
尝试解释这部分
默认情况下,您有权访问同一域的所有数据,但没有其他域的权限。
当你添加
这基本上就是“向服务器请求用户‘匿名’的许可”。服务器可以授予权限,也可以不授予权限。这取决于服务器。这包括询问同一域上的服务器,这意味着如果您要请求同一域上的歌曲,您需要 (a) 删除上面的行或 (b) 配置您的服务器以授予 CORS 权限。 大多数服务器不授予 CORS 权限,因此如果您添加该行,即使服务器是同一域,如果它不授予 CORS 权限,则尝试分析音频将失败。
正如
音乐:DOCTOR VOX - 升级
Making something audio reactive is pretty simple. Here's an open source site with lots audio reactive examples.
As for how to do it you basically use the Web Audio API to stream the music and use its AnalyserNode to get audio data out.
Then it's just up to you to draw something creative.
note some troubles you'll likely run into.
At this point in time (2017/1/3) neither Android Chrome nor iOS Safari support analysing streaming audio data. Instead you have to load the entire song. Here'a a library that tries to abstract that a little
On Mobileyou can not automatically play audio. You must start the audio inside an input event based on user input like'click'
or'touchstart'
.As pointed out in the sample you can only analyse audio if the source is either from the same domain OR you ask for CORS permission and the server gives permission. AFAIK only Soundcloud gives permission and it's on a per song basis. It's up to the individual artist's song's settings whether or not audio analysis is allowed for a particular song.
To try to explain this part
The default is you have permission to access all data from the same domain but no permission from other domains.
When you add
That basically says "ask the server for permission for user 'anonymous'". The server can give permission or not. It's up to the server. This includes asking even the server on the same domain which means if you're going to request a song on the same domain you need to either (a) remove the line above or (b) configure your server to give CORS permission. Most servers by default do not give CORS permission so if you add that line, even if the server is the same domain, if it does not give CORS permission then trying to analyse the audio will fail.
music: DOCTOR VOX - Level Up
通过 WebGL“尚未准备好”,我假设您指的是渗透(目前仅在 WebKit 和 Firefox 中支持)。
除此之外,使用 HTML5 音频和 WebGL 绝对可以实现均衡器。一位名叫 David Humphrey 的人在博客中介绍了如何使用 WebGL 制作不同的音乐可视化工具,并且能够创建一些确实令人印象深刻的。以下是一些可视化视频(点击观看):
By WebGL being "not ready", I'm assuming that you're referring to the penetration (it's only supported in WebKit and Firefox at the moment).
Other than that, equalisers are definitely possible using HTML5 audio and WebGL. A guy called David Humphrey has blogged about making different music visualisers using WebGL and was able to create some really impressive ones. Here's some videos of the visualisations (click to watch):
我使用 SoundManager2 从 mp3 文件中提取波形数据。该功能需要 Flash 9,因此它可能不是最好的方法。
我使用 HMTL5 Canvas 进行的波形演示:
http://www.momentumracer.com/electriccanvas/
和 WebGL:
http://www.momentumracer.com/electricwebgl/
来源:
https://github.com/pepez/Electric-Canvas
I used SoundManager2 to pull the waveform data from the mp3 file. That feature requires Flash 9 so it might not be the best approach.
My waveform demo with HMTL5 Canvas:
http://www.momentumracer.com/electriccanvas/
and WebGL:
http://www.momentumracer.com/electricwebgl/
Sources:
https://github.com/pepez/Electric-Canvas
根据复杂性,您可能有兴趣尝试Processing(http://www.processing.org),它具有非常简单的工具来制作基于Web的应用程序,并且它具有获取音频文件的FFT和波形的工具。
Depending on complexity you might be interested in trying out Processing (http://www.processing.org), it has really easy tools to make web-based apps, and it has tools to get the FFT and waveform of an audio file.