Question

my application allow a user to speak and I'm trying to build the amplitudes graph live while the user speaks. I'm doing so by using AsyncTask that sample the MediaRecorder or AudioRecorder (I tried them both) every x milliseconds. Even if I sample every millisecond, 10 milliseconds or 100 milliseconds most of the returns values are 0 although I'm speaking all the time in the tests. The array of values looks like this: [ 0, 0, 1500, 0, 0, 0, 0, 0, 3000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 300, 0, 0, 0, 0, 0, 150, 0, 0, 0, 0, 0... ] well you get my point. Am I missing something? Thank you.

Edit: it seems that if I sampling every 100 milliseconds I get something more like this: [5000, 6000, 7000, 0, 4500, 5000, 0, 7000, 7000, 7500, 8000, 0, 7000] it's fewer zeros than the 10 milliseconds sampling but there are still zeros there.

Was it helpful?

Solution

After investigating I figured out that this has a direct connection to the sampling rate (may be obvious but I skip it somehow).

So, setting this will output a solid number every 100 milliseconds:

this.mediaRecorder.setAudioSamplingRate(8000);

this every 40 milliseconds:

this.mediaRecorder.setAudioSamplingRate(16000);

and this every 10 milliseconds:

this.mediaRecorder.setAudioSamplingRate(44100);

Just remember that you can use 44100 as a sampling rate for AAC audio encoder and 16000 for AMR_WB. The AMR_NB only supports 8000 as the sampling rate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top