试图检测沉默。使用以下代码。我的目标是将所有录制的数据转换为我实现的.wav文件,但现在我想在检测到静音时停止录制。这可以实现吗?
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();