如何录制音频android上的磨损 [英] How to record audio on android wear
问题描述
有一些方法来记录声音在Android上穿?我用AudioRecord API和它的应用程序崩溃。
我是不是做错了什么?
短[] audioData =新的短[minBufferSize]
AudioRecord audioRecord =新AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);
audioRecord.startRecording();
同时,(录音){
INT numberOfShort = audioRecord.read(audioData,0,minBufferSize);
的for(int i = 0; I< numberOfShort;我++){
dataOutputStream.writeShort(audioData [I]);
}
}
audioRecord.stop();
解决方案
AudioRecord支持,并适用于Android Wear
构建AudioRecord后,您应该检查状态,确认初始化成功尝试记录之前。
audioRecord.getState()== AudioRecord.STATE_INITIALIZED
此外,还应确保您在清单中的正确的权限。您需要android.permission.RECORD_AUDIO最低限度以及任何权限,你正在写文件的位置。
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.
这篇关于如何录制音频android上的磨损的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!