在 Java 中将声音 (.wav/.mp3) 显示为图形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1062968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display sound (.wav/.mp3) as graph in Java
提问by William
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 中有什么可以帮助我的吗?
采纳答案by William
In the end I found code to do exactly what I wanted in Chapter 10 of the book Swing Hacks.
最后,我在Swing Hacks一书的第 10 章中找到了完全按照我想要的代码。
回答by Marcin
In Java Sound API poke around AudioSystem.getAudioInputStream which will return AudioInputStreamwhich 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 文件等)。

