There is some way to record audio on android wear? I used AudioRecord API and it crashes the application.
Am I doing something wrong?
short[] audioData = new short[minBufferSize];
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);
audioRecord.startRecording();
while(recording){
int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
for(int i = 0; i < numberOfShort; i++){
dataOutputStream.writeShort(audioData[i]);
}
}
audioRecord.stop();
AudioRecord is supported and works on Android Wear. If you are testing on an emulator it is possiblly not supporting the sample rate you are supplying, 11025, try another such as 8000.
After constructing AudioRecord, you should check the state to confirm initialization was successful before trying to record.
audioRecord.getState() == AudioRecord.STATE_INITIALIZED
Also ensure you have the correct permissions in the manifest. You will need android.permission.RECORD_AUDIO as a minimum and also any permissions for the location you are writing the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With