AudioTrack 读取 PCM
import android.media.AudioFormat;
import android.media.AudioTrack;
/**
* 读取 PCM 音频流
*
* @param filePath
* @return
*/
static byte[] getPCMStream(String filePath) {
List<Byte> stream = new ArrayList<>();
int bufferSize = AudioTrack.getMinBufferSize(16000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
FileInputStream fis = null;
try {
fis = new FileInputStream(filePath);
byte[] buffer = new byte[bufferSize];
while (fis.read(buffer) != -1) {
for (byte bf : buffer) {
stream.add(bf);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Bytes.toArray(stream);
}