使用
您好,我目前正在开发一个用纯 HTML5 和 Javascript 编写的音频波形编辑器。
我使用 Mozilla
作为波形编辑器,我的程序必须在当前播放之前查找并预处理大约几秒钟的数据,即播放 00:05:00 时,我的程序可能应该显示从 00:04:50 到 00:05 的波形:10,所以我必须在播放之前对 00:05:00 和 00:05:10 之间的数据进行预处理。
我在网上搜索了解决方案(不限于Mozilla的方法,Chrome或Opera的方法也可以接受),但没有得到答案。 preload 属性和 onprogress 事件没有帮助。现在我正在尝试制作另一个 标签,它播放与原始标签相同的音乐,但速度要快几秒钟,以便提前获取数据。然而,正如您所看到的,该解决方案非常脏。
我想知道 HTML5 小组是否正在研究一些更灵活的方法来处理多媒体对象,或者是否有一些浏览器开发团队正在研究这个。如果您对此主题有任何想法或经验,请给我一些指示。谢谢。
更新:
也许我没有清楚地描述我的问题。下面是从 Audacity 拍摄的一张照片,它可以证明我的目标。
大约 1:55.10 处的垂直线表示当前正在播放的帧。对于该行左侧的帧,我可以使用我的程序保存的历史帧。但是对于该行右侧尚未播放的帧,我无法在播放之前获取它们。
一个丑陋的解决方案可能是添加另一个 标签,它的播放速度比原始标签快(应该在屏幕截图中播放 1:55.90),以便我可以将帧放在垂线。但这很丑陋,而且不容易实现,不是吗?
Hi I'm currently working on an audio waveform editor written in pure HTML5 w/ Javascript.
I've made some progress using the <audio>
.MozAudioAvailable event from Mozilla, to get the data in each frame and draw them on a canvas. However with MozAudioAvailable I can only get the frame which it is NOW playing.
As a waveform editor, my program have to seek and preprocess the data about several seconds PRIOR TO the currently playing, i.e. when playing 00:05:00, my program should probably be showing the waveform from 00:04:50 to 00:05:10, so I have to preprocess the data between 00:05:00 and 00:05:10 before they got played.
I've searched the Internet to get a solution (not restricted to the Mozilla approaches, Chrome or Opera ones are also accepted), but got no answer. The preload property and onprogress event doesn't help. Now I'm trying to make another <audio>
tag which plays the same music as the original one, but several seconds faster to get the data in advance. However the solution is quite dirty as you seen.
I'm wondering if HTML5 group is working on some more flexible ways to deal with the multimedia objects, or if some browser development team is working on this. If you have any idea or experience on this topic, plz give me some instructions. Thx.
UPDATE:
Maybe I have not described my question clearly. Below is a picture taken from Audacity which may demonstrate my target.
The vertical line at about 1:55.10 indicates the frame currently playing. For frames to the left of the line, I can use the historical frames saved by my program. But for frames to the right of the line, which have not yet been played, I'm not able to get them before they've been played.
An ugly solution may be to add another <audio>
tag which plays faster than the original one (should be playing 1:55.90 in the screenshot) so that I can get the frames to the right of the vertical line. But that's ugly, and not easy to implement, isn't it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 https://wiki.mozilla.org/Audio_Data_API
您要查找的数据位于帧缓冲区中传递给侦听器函数的事件对象的属性
要访问历史数据的特定部分,只需缓存自己捕获的先前帧缓冲区即可。
附录:
好的,所以您需要您的程序展望未来。据我所知,除非您可以使用某种巧妙的预加载解决方案,否则这是不可行的(尽管我怀疑这也行不通 - 也许订阅 moz 邮件列表可以让您请求将此作为未来的功能) )。
我仍然不知道你到底想做什么,但我有一个 HTML5 播放器,它使用绘制的波形背景,并在播放期间使用我自己从服务器上的音频文件中提取的原始音频数据绘制示波器- 我不使用 mozilla API,因为我希望它能够在所有支持 ogg 的浏览器中工作,因此我完全加载一个单独的数据 blob。这当然意味着 a) 它不是纯 HTML5 和 Javascript,b) 我的播放器仅播放源自我的服务器的文件。无论如何,这些阶段是:
1)使用命令行实用程序(我推荐 sox)来提取 RAW 数据 - 我将其混合为单声道、8 位 1khz PCM,它相对较小,但分辨率足够高,可以使用( 1kb/秒)。如果您想保留它(在非 Mozilla 浏览器中播放时绘制示波器),请将其作为 Blob 缓存在数据库中。
2) 使用 RAW PCM 使用 php_gd 绘制波浪的 PNG,并缓存它(用于您的播放器背景)
3) 如果使用 RAW 数据,那么您可以将其作为 base64 编码的字符串加载到 javascript 中
这并非不可能如果您仅使用服务器作为提取原始数据的代理,即使使用外部音频文件,您也可以执行此操作,但随后您将需要注意由此引入的安全问题。
如果这适用于您,请告诉我,我将发布一些源代码。
一旦我整理完毕,该程序将作为开源项目发布在 http://jukenix.org有点。
PS 实际操作的屏幕截图位于上面链接的页面底部
From https://wiki.mozilla.org/Audio_Data_API
The data you're looking for is in the framebuffer property of the event object passed to your listener function
To access a particular section of historical data, simply cache previous framebuffer captures yourself
ADDENDUM:
OK, so you need your program to look into the future. As far as I know, this isn't doable unless you can use some kind of clever preload solution (although I suspect this won't work either - perhaps a subscription to the moz mailing list may enable you to request this as a future feature).
I still don't know what exactly it is you're trying to do, but I have an HTML5 player that uses a drawn waveform background and draws an oscilloscope during playback using RAW audio data which I rip from the audio file myself on the server - I don't use the mozilla API because I want it to work in all ogg-supporting browsers, so I load a separate data blob altogether. This of course means a) it is not pure HTML5 and Javascript, and b) my player only plays files that originate from my server. In any case, the stages are:
1) Use a command-line utility (I recommend sox) to extract the RAW data - I downmix it to mono, 8-bit 1khz PCM which is relatively small yet high enough resolution to be useful (1kb/sec). If you want to keep it (to draw an oscilloscope during playback in non-mozilla browsers) cache it in a database as a blob.
2) Use the RAW PCM to draw a PNG of the wave using php_gd, and cache that (for your player background)
3) if using the RAW data then you can load it into javascript as a base64-encoded string
It is not impossible for you to do this even with external audio files if you use your server simply as a proxy to extract the RAW data, but then you will need to take care of the security issues that introduces.
If this applies to you at all then let me know and I'll post some source code for these.
The program in question will be released as an open source project at http://jukenix.org as soon as I've tidied it up a bit.
P.S. screenshot of this in action is at bottom of page of link above