爪哇 - 读,操纵和写入WAV文件

问题描述:

在Java程序中,有什么是读取音频文件( WAV 文件)的数组的最佳方式数字(浮动[] 短[] ,...),并写入来自一个数组WAV文件数字?

In a Java program, what is the best way to read an audio file (WAV file) to an array of numbers (float[], short[], ...), and to write a WAV file from an array of numbers?

在你想达成的目标将是有益的东西一些细节。如果原始WAV数据是正常的你,只需使用一个FileInputStream,并可能是一个扫描仪把它变成数字。但是,让我试着给你一些有意义的样本code,让你开始:

Some more detail on what you'd like to achieve would be helpful. If raw WAV data is okay for you, simply use a FileInputStream and probably a Scanner to turn it into numbers. But let me try to give you some meaningful sample code to get you started:

有一个名为com.sun.media.sound.WaveFileWriter用于此目的的类。

There is a class called com.sun.media.sound.WaveFileWriter for this purpose.

InputStream in = ...;
OutputStream out = ...;

AudioInputStream in = AudioSystem.getAudioInputStream(in);

WaveFileWriter writer = new WaveFileWriter();
writer.write(in, AudioFileFormat.Type.WAVE, outStream);

您可以实现自己的AudioInputStream,它无论巫术把你的电话号码数组为音频数据。

You could implement your own AudioInputStream that does whatever voodoo to turn your number arrays into audio data.

writer.write(new VoodooAudioInputStream(numbers), AudioFileFormat.Type.WAVE, outStream);

由于 @stacker 提到的,你应该让自己熟悉课程的API。

As @stacker mentioned, you should get yourself familiar with the API of course.