How to record audio on android wear

半腔热情 提交于 2019-12-04 08:54:10

问题


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();

回答1:


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.



来源:https://stackoverflow.com/questions/28321405/how-to-record-audio-on-android-wear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!