从音频渲染图像

发布于 2024-08-19 10:39:16 字数 199 浏览 9 评论 0 原文

是否可以渲染音频文件的可视化?

也许使用 SoundManager2 / Canvas / HTML5 音频? 你懂一些技术吗?

我想创建这样的东西:

alt text

Is there a possibility to render an visualization of an audio file?

Maybe with SoundManager2 / Canvas / HTML5 Audio?
Do you know some technics?

I want to create something like this:

alt text

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

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

发布评论

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

评论(5

梅倚清风 2024-08-26 10:39:17

通过 FFT 运行样本,然后将给定频率范围内的能量显示为给定点处的图形高度。您通常希望频率范围从左侧的 20 Hz 左右到右侧的采样率/2 左右(如果采样率超过 40 KHz,则为 20 KHz)。

不过我不太确定是否要在 JavaScript 中执行此操作。不要误会我的意思:JavaScript 完全能够实现 FFT——但我完全不确定是否可以实时实现。 OTOH,对于用户查看来说,每秒更新大约 5-10 次就可以了,这可能是一个更容易达到的目标。例如,每 200 毫秒更新 20 毫秒的样本可能是合理的希望,但我当然不能保证您能够跟上。

Run samples through an FFT, and then display the energy within a given range of frequencies as the height of the graph at a given point. You'll normally want the frequency ranges going from around 20 Hz at the left to roughly the sampling rate/2 at the right (or 20 KHz if the sampling rate exceeds 40 KHz).

I'm not so sure about doing this in JavaScript though. Don't get me wrong: JavaScript is perfectly capable of implementing an FFT -- but I'm not at all sure about doing it in real time. OTOH, for user viewing, you can get by with around 5-10 updates per second, which is likely to be a considerably easier target to reach. For example, 20 ms of samples updated every 200 ms might be halfway reasonable to hope for, though I certainly can't guarantee that you'll be able to keep up with that.

缪败 2024-08-26 10:39:17

http://ajaxian.com/archives/amazing-audio- Sample-in-javascript-with-firefox

查看源代码以了解他们如何可视化音频

http://ajaxian.com/archives/amazing-audio-sampling-in-javascript-with-firefox

Check out the source code to see how they're visualizing the audio

别挽留 2024-08-26 10:39:17

这还不可能,除非以二进制数据的形式获取音频并解压 MP3(不是 JavaScript 的强项),或者也许使用 Java 或 Flash 提取您需要的信息位(似乎是可能的)但这似乎也比我个人想要承担的更令人头痛)。

但您可能对 Dave Humphrey 的音频实验感兴趣,其中包括一些很酷的可视化内容。他通过修改浏览器源代码并重新编译来做到这一点,因此这对您来说显然不是一个现实的解决方案。但这些实验可能会导致将来向 元素添加新功能。

This isn't possible yet except by fetching the audio as binary data and unpacking the MP3 (not JavaScript's forte), or maybe by using Java or Flash to extract the bits of information you need (it seems possible but it also seems like more headache than I personally would want to take on).

But you might be interested in Dave Humphrey's audio experiments, which include some cool visualization stuff. He's doing this by making modifications to the browser source code and recompiling it, so this is obviously not a realistic solution for you. But those experiments could lead to new features being added to the <audio> element in the future.

救赎№ 2024-08-26 10:39:17

为此,您需要进行傅里叶变换(查找 FFT),这在 javascript 中会很慢,而且目前不可能实时进行。

如果您确实想在浏览器中执行此操作,我建议在 java/silverlight 中执行此操作,因为它们在浏览器中提供最快的数字处理速度。

For this you would need to do a Fourier transform (look for FFT) which will be slow in javascript, and not possible in realtime at present.

If you really want to do this in the browser, I would suggest doing it in java/silverlight, since they deliver the fastest number crunching speed in the browser.

镜花水月 2024-08-26 10:39:16

您在这里有一些示例和教程:http://www.html5rocks.com/en/ tutorials/#webaudio

目前,它可以在最后的 Chrome 和最后的 Firefox(Opera?)中运行。

演示:http://www.chromeexperiments.com/tag/audio/

立即执行,对于网站的所有访问者,您可以检查通过 Flash“代理”访问音频数据的 SoundManagerV2.js http://www.schillmania.com/projects/soundmanager2/demo/api/ (他们已经在开发 HTML5 音频引擎,一旦主要浏览器实现它就会发布它)

您可以在画布上绘制 3 种不同的音频数据:波形、均衡器和峰值。

soundManager.defaultOptions.whileplaying = function() { // AUDIO analyzer !!!
    $document.trigger({ // DISPATCH ALL DATA RELATIVE TO AUDIO STREAM // AUDIO ANALYZER 
        type             : 'musicLoader:whileplaying',
        sound            : {
            position         : this.position,          // In milliseconds
            duration         : this.duration,
            waveformDataLeft : this.waveformData.left, // Array of 256 floating-point (three decimal place) values from -1 to 1
            waveformDataRight: this.waveformData.right,
            eqDataLeft       : this.eqData.left,       // Containing two arrays of 256 floating-point (three decimal place) values from 0 to 1
            eqDataRight      : this.eqData.right,      // ... , the result of an FFT on the waveform data. Can be used to draw a spectrum (frequency range)
            peakDataLeft     : this.peakData.left,     // Floating-point values ranging from 0 to 1, indicating "peak" (volume) level
            peakDataRight    : this.peakData.right
        }
    });
};

使用 HTML5,您可以获得:

var freqByteData = new Uint8Array(analyser.frequencyBinCount);
var timeByteData = new Uint8Array(analyser.frequencyBinCount);
function onaudioprocess() {
    analyser.getByteFrequencyData(freqByteData);
    analyser.getByteTimeDomainData(timeByteData);
    /* draw your canvas */
}

工作时间到了! ;)

You have a tone of samples and tutorials here : http://www.html5rocks.com/en/tutorials/#webaudio

For the moment it work in the last Chrome and the last last Firefox (Opera ?).

Demos : http://www.chromeexperiments.com/tag/audio/

To do it now, for all visitors of a web site, you can check SoundManagerV2.js who pass through a flash "proxy" to access audio data http://www.schillmania.com/projects/soundmanager2/demo/api/ (They already work on the HTML5 audio engine, to release it as soon as majors browsers implement it)

Up to you for drawing in a canvas 3 differents audio data : WaveForm, Equalizer and Peak.

soundManager.defaultOptions.whileplaying = function() { // AUDIO analyzer !!!
    $document.trigger({ // DISPATCH ALL DATA RELATIVE TO AUDIO STREAM // AUDIO ANALYZER 
        type             : 'musicLoader:whileplaying',
        sound            : {
            position         : this.position,          // In milliseconds
            duration         : this.duration,
            waveformDataLeft : this.waveformData.left, // Array of 256 floating-point (three decimal place) values from -1 to 1
            waveformDataRight: this.waveformData.right,
            eqDataLeft       : this.eqData.left,       // Containing two arrays of 256 floating-point (three decimal place) values from 0 to 1
            eqDataRight      : this.eqData.right,      // ... , the result of an FFT on the waveform data. Can be used to draw a spectrum (frequency range)
            peakDataLeft     : this.peakData.left,     // Floating-point values ranging from 0 to 1, indicating "peak" (volume) level
            peakDataRight    : this.peakData.right
        }
    });
};

With HTML5 you can get :

var freqByteData = new Uint8Array(analyser.frequencyBinCount);
var timeByteData = new Uint8Array(analyser.frequencyBinCount);
function onaudioprocess() {
    analyser.getByteFrequencyData(freqByteData);
    analyser.getByteTimeDomainData(timeByteData);
    /* draw your canvas */
}

Time to work ! ;)

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