Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record audio on android wear

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();
like image 549
Leonardo Cartaxo Avatar asked Feb 04 '15 12:02

Leonardo Cartaxo


1 Answers

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.

like image 181
BrentM Avatar answered Oct 09 '22 16:10

BrentM