使用Android AudioRecord 錄制PCM文件,android SDK保證在所有設備上都支持的采樣頻率只有44100HZ,
所以如果想得到其他采樣頻率的PCM數據,有幾種方式:
1.在設備上嘗試可用的采樣頻率,
2.使用44.1K采樣后轉換采樣頻率。
其中第二種轉換采樣頻率的操作,有很多種方法。目前我使用的是SSRC,效果很好。
private void simpleDownSample() {
File BeforeDownSampleFile = new File(RawRecordFilePath);
File DownSampled = new File(DownSampledFilePath);
try {
FileInputStream fileInputStream = new FileInputStream(BeforeDownSampleFile);
FileOutputStream fileOutputStream = new FileOutputStream(DownSampled);
new SSRC(fileInputStream, fileOutputStream, 44100, 8000,
2,
2,
1, Integer.MAX_VALUE, 0, 0, true);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
上述代碼中的8000是目標采樣頻率。
SSRC官網:http://shibatch.sourceforge.net/
JSSRC:https://github.com/hutm/JSSRC