如何使用 JavaSound (Java, Java Sound) 从 .wave 文件中读取信息 [英] How can I read info from .wave file using JavaSound (Java, Java Sound)

查看:50
本文介绍了如何使用 JavaSound (Java, Java Sound) 从 .wave 文件中读取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 .wave 文件中读取 SampleRate、SignalFrequency 和 Amplitude.我如何使用 JavaSound 做到这一点?

Hi I need to read SampleRate, SignalFrequency and Amplitude from .wave file. How can I do that using JavaSound?

推荐答案

您可以通过获取 AudioFormat 对象的句柄来获取采样率:

You can get the sampling rate by getting a handle on the AudioFormat object:

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();

至于幅度,基本上是原始 .wav 文件数据,您可以通过调用其任何 read() 方法直接从 audioInputStream 访问.

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.

这篇关于如何使用 JavaSound (Java, Java Sound) 从 .wave 文件中读取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆