Android AudioRecord initialization fails every time
I spent some hours solving this problem, and found out that moving
<uses-permission android:name="android.permission.RECORD_AUDIO" />
outside the application block actually solved it!
... </application> <uses-permission android:name="android.permission.RECORD_AUDIO" /> </manifest>
Another possible issue:
I had the RECORD_AUDIO
permission enabled in my manifest, but for API level 23 I had to also request the permission at runtime.
Try 16bit. This is what works for me:
try { // Create a new AudioRecord object to record the audio. bufferSize = AudioRecord.getMinBufferSize(frequency,channelConfiguration,audioEncoding); audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency, channelConfiguration, audioEncoding, bufferSize); } catch (Throwable t) { Log.e("AudioRecord","Recording Failed"); }
And I have the following variables set:
int frequency = 8000;int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;