简体   繁体   English

如何使用JavaSound(Java,Java Sound)从.wave文件读取信息

[英]How can I read info from .wave file using JavaSound (Java, Java Sound)

Hi I need to read SampleRate, SignalFrequency and Amplitude from .wave file. 嗨,我需要从.wave文件读取SampleRate,SignalFrequency和Amplitude。 How can I do that using JavaSound? 如何使用JavaSound做到这一点?

You can get the sampling rate by getting a handle on the AudioFormat object: 您可以通过获取AudioFormat对象的句柄来获得采样率:

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("test.wav"));
AudioFormat audioFormat = audioInputStream.getFormat();

Once you have that, you can get the sample rate as follows: 一旦有了,就可以按以下方式获得采样率:

float sampleRate = audioFormat.getSampleRate();

As for the amplitude, that is basically the raw .wav file data, which you can access directly from the audioInputStream by calling any of its read() methods. 至于振幅,基本上就是原始的.wav文件数据,您可以通过调用任何read()方法直接从audioInputStream访问该数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM