I use audioRecord instead of mediarecorder, it works fine in my application, but I have logic that is very dependent on the maximum amplitude, which is very difficult to get with the audio editor, this is what I use when reading the buffer
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(); } } }
but this does not work for me, as the value changes very quickly. I need to implement something like getMaxAmplitude () for audioRecord.
Aashish bhatnagar
source share