Can the Android emulator record and play back audio using pc hardware?

余生颓废 提交于 2019-11-26 23:11:37
Tom

Recording audio is possible at least in the standard 2.3.3 emulator on Windows 7; I have tried it and it works. However, the recorded audio did sound a bit weird (slow) in my case. I did not investigate the cause.

You need to add audio recording + playback support to the emulator (Android SDK and AVD manager -> Virtual devices -> Edit -> Hardware -> New). Then use the [MediaRecorder API][1] to record (MediaRecorder.AudioSource.MIC).

Code is:

fMediaRecorder= new MediaRecorder();
fMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
fMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
fMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

fMediaRecorder.setAudioChannels(1);
fMediaRecorder.setAudioSamplingRate(8000);

fMediaRecorder.setOutputFile(fTmpFile.getAbsolutePath());

fMediaRecorder.prepare();

fMediaRecorder.start();

You also need

<uses-permission android:name="android.permission.RECORD_AUDIO"/> 

in your AndroidManifest.xml

Works for me, but Audio IS distorted.

Mno

To the best of my knowledge: To be able to use MediaRecorder you need to build the entire source so that you can use the recording facility, along with the option that you have mentioned.

  • Get the source code of the version of android that you are targeting.
  • Build the generic image by :
    1. . build/envsetup.sh
    2. lunch 1 (ie. choose the generic option, not simulator)
    3. make -j<number> where number = #cores supported by your pc; exclude the angle brackets
  • cd out/target/.../generic, ... represents the rest of the path upto generic; set environment variable ANDROID_PRODUCTION_OUT to this directory.
  • run the emulator from the out/host/.../bin directory with the -audio option.

This should ideally work.

The default sdk does not support your use case, as you have rightly mentioned here.

No. It is not possible to use the emulator for recording sound. You will have to code the logic of your program and then to deploy the actual apk to your phone, in order to test its functionality.

Please check this link as it has the official reference for my comment: http://developer.android.com/intl/es/guide/topics/media/audio-capture.html

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