Trying to detect silence. Used the following code. My objective is to convert all recorded data to .wav file which I achieved, but now i want to make recording stop when detecting silence. Is this achievable?
mAud.startRecording();
while (mIsRecording) {
ByteBuffer buffer = ByteBuffer.allocateDirect(mBufferSize * 2);
numSamples = mAud.read(buffer, mBufferSize * 2);
if (numSamples == AudioRecord.ERROR_INVALID_OPERATION) {
throw new IllegalStateException(
"read() returned AudioRecord.ERROR_INVALID_OPERATION");
} else if (numSamples == AudioRecord.ERROR_BAD_VALUE) {
throw new IllegalStateException(
"read() returned AudioRecord.ERROR_BAD_VALUE");
}
if (numSamples > 0)
addBuffer(buffer, numSamples / 2);
}
mAud.stop();
mAud.release();