1

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();
JibinNajeeb
  • 784
  • 1
  • 10
  • 31
  • How long is the audio clip you are checking to be silent? – byxor Aug 29 '16 at 13:51
  • It'd be useful to break your problem down into smaller ones. First of all let's ask **"How do I detect if an entire audio clip is silent?"** I imagine you could do this by getting the average amplitude and asserting that the result is less than a very low volume. Try implementing and testing that method? – byxor Aug 29 '16 at 14:05
  • I think there is some algorithm to detect silence. I checked this post http://stackoverflow.com/questions/5800649/detect-silence-when-recording. But this mentioning about PCM audio which I dont what it is. In the above code each time when loop execute I can read data and check for silence(say some value = 0) if this value is true for 2 sec then i can break the loop. Is this achievable, I dont know whether this is stupid? – JibinNajeeb Aug 29 '16 at 14:14
  • It sounds like it would work to me but I think it could probably be structured better. I'm not really sure, I'll leave it with everyone else. – byxor Aug 29 '16 at 14:15
  • Maybe this will help answer your question: https://sound.stackexchange.com/questions/42299/what-dbfs-threshold-should-i-set-for-differentiation-between-silence-and-not-sil/42304#42304 – Sushovan Mandal Nov 08 '17 at 06:30

0 Answers0