【发布时间】:2012-07-28 10:19:51
【问题描述】:
我在我的应用程序中使用 audioRecord 而不是 mediarecorder,它工作正常,但我有一个高度依赖于最大振幅的逻辑,使用音频记录很难获得这里是我在读取缓冲区时使用的
private void writeAudioDataToFile(){
byte data[] = new byte[bufferSize];
String filename = getTempFilename();
FileOutputStream os = null;
try {
os = new FileOutputStream(filename);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int read = 0;
max=0;
if(null != os){
while(isRecording){
read = recorder.read(buffer, 0, bufferSize);
int ab = (buffer[0] & 0xff) << 8 | buffer[1];
amplitude = Math.abs(ab);
if(amplitude>0&&litude<25000)
isSilence=true;
else
isSilence=false;
//System.out.println(">>>>>>>>>>>"+amplitude);
if(AudioRecord.ERROR_INVALID_OPERATION != read){
try {
os.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
但这对我不起作用,因为值变化非常快,我需要为 audioRecord 实现 getMaxAmplitude() 之类的东西。
【问题讨论】:
标签: java android android-audiorecord