Recording sound in android

老子叫甜甜 提交于 2020-01-25 09:45:12

问题



I'd like to know how to record sound for a specific amount of time, without saving it to a file - holding in a byte stream for example. Also, if possible, make it look like an AMR file. I've tried to search google, and also wrote some code myself, but had no success. If you can link me to a page that explains how to do so, or give an example, it would be very nice of you :)

Thanks.


回答1:


MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setOutputFile(fileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

recorder.prepare();
recorder.start();

I'm not sure if you can skip the setOutputFile step and keep the recording in memory (probably not).



来源:https://stackoverflow.com/questions/5605418/recording-sound-in-android

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