从 MP3SPI 的文档:
File file = new File(filename);
AudioInputStream in= AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
然后,您只需从中读取数据 - 它将是“原始”数据,如.(有关详细信息,请参阅 AudioFormat
的文档。din
decodedFormat
(请注意,此示例代码不会关闭流或类似内容 - 像往常一样使用适当的 try/final 块。