Pause Detection
Hi Kaarel, I needed a solution for pause detection in my app and your solution is the best one I've found. Good work and thanks for sharing. I've abstracted it so it's easier to include anywhere.
The issue is with the MediaRecorder.AudioSource type and how differently it behaves between MIC and VOICE_RECOGNITION and across various devices. I've added a PAUSE_IGNORE_TIME to prevent the immediate reports of pause scores > 100 being triggered, until the results appear to settle down to below PAUSE_THRESHOLD = 7.
Not sure if the threading and synchronisation is a little too much, but seems to work fine.
Hope constructing it as a separate entity will help perfect it.
I've also added my standard logging class, as I couldn't be bothered to remove it all from my code :)
Ben
Edited the gist - line 125 on PauseDetector - detection should have been wrapped in else {}
Thanks Ben! I'll try to integrate your contribution at some point. (You're also welcome to offer it as a pull request.)
I never tested my pause detection with different audio sources nor with many different devices. I know that it has problems with background noise. So, I've viewed it as a temporary solution that will have to be replaced with something more serious in the future. (Possibly Android itself would offer a builtin solution at some point.)