在Java中将声音(.wav / .mp3)显示为图形

时间:2021-09-01 19:44:59

I need to display a graph of a sound file - i.e. a wave form as displayed by audio editors such as Audacity.

我需要显示声音文件的图形 - 即由Audacity等音频编辑器显示的波形。

How should I go about this? Is there anything in the Java Sound API that can help me?

我该怎么办呢? Java Sound API中有什么可以帮助我吗?

2 个解决方案

#1


In Java Sound API poke around AudioSystem.getAudioInputStream which will return AudioInputStream which shows you how to open audio files form within Java. It is good enough to read .wav files, but not quite so for mp3s.

在Java Sound API中,围绕AudioSystem.getAudioInputStream,它将返回AudioInputStream,它向您展示如何在Java中打开音频文件。读取.wav文件已经足够了,但对于mp3来说并不是这样。

It lets you read bytes one by one directly. Also getAudioFormat will return object that has sample rate, bit/sample, etc. After reading your waveform you can draw it in your favorite way on the screen (Swing, AWT, png file on the web, etc.).

它允许您直接逐个读取字节。此外,getAudioFormat将返回具有采样率,位/样本等的对象。读取波形后,您可以在屏幕上以您喜欢的方式绘制它(Swing,AWT,网络上的png文件等)。

#2


In the end I found code to do exactly what I wanted in Chapter 10 of the book Swing Hacks.

最后,我发现代码在Swing Hacks一书的第10章中完全符合我的要求。

#1


In Java Sound API poke around AudioSystem.getAudioInputStream which will return AudioInputStream which shows you how to open audio files form within Java. It is good enough to read .wav files, but not quite so for mp3s.

在Java Sound API中,围绕AudioSystem.getAudioInputStream,它将返回AudioInputStream,它向您展示如何在Java中打开音频文件。读取.wav文件已经足够了,但对于mp3来说并不是这样。

It lets you read bytes one by one directly. Also getAudioFormat will return object that has sample rate, bit/sample, etc. After reading your waveform you can draw it in your favorite way on the screen (Swing, AWT, png file on the web, etc.).

它允许您直接逐个读取字节。此外,getAudioFormat将返回具有采样率,位/样本等的对象。读取波形后,您可以在屏幕上以您喜欢的方式绘制它(Swing,AWT,网络上的png文件等)。

#2


In the end I found code to do exactly what I wanted in Chapter 10 of the book Swing Hacks.

最后,我发现代码在Swing Hacks一书的第10章中完全符合我的要求。