How to record audio on android wear

Is there any way to record audio for android wear? I used the AudioRecord API and the application crashed.

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(); 
+7
java android android-wear android-audiorecord
source share
1 answer

AudioRecord is supported and runs on Android Wear. If you are testing an emulator, you cannot support the sampling rate that you are submitting, 11025, try another one, for example 8000.

After creating AudioRecord, you should check the status to confirm that the initialization was successful before trying to record.

 audioRecord.getState() == AudioRecord.STATE_INITIALIZED 

Also make sure you have the correct permissions in the manifest. You will need android.permission.RECORD_AUDIO as a minimum, as well as any permissions for the location where you are writing the file.

+6
source share

All Articles