且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从wav文件中获取PCM数据?

更新时间:2022-06-24 22:38:12

这可以通过完成Java Sound API。


  • 使用 AudioSystem 获取 AudioInputStream 。

  • 查询 AudioFormat 的流。

  • 创建 byte [] 以适应格式。例如。 8位单声道是字节[1] 。 16位立体声是 byte [4]

  • 读取 byte [] 并且它将逐帧包含声音。

  • 继续进行处理..

  • Use the AudioSystem to get an AudioInputStream from the file.
  • Query the stream for the AudioFormat.
  • Create a byte[] to suit the format. E.G. 8 bit mono is a byte[1]. 16 bit stereo is byte[4].
  • Read the stream in chunks of the byte[] and it will contain the sound, frame by frame.
  • Proceed with further processing..