I don't have an android phone, but i'm trying to develop for it anyway. The only way to test my application at the moment is to use the emulator, which I've read does not support audio recording. However, I read about the startup command "-audio " which allows audio input/output from your pc using the 'winaudio' backend. I haven't been able to get it to work though, is it possible to record using my pc's microphone? If so, what am I doing wrong?
4 Answers
Yes, it can. On Mac OSX, you must set the microphone on the emulator settings, after it's opened.
While the emulator is opened, on the right side bar (where the volume buttons are localized), click on the three dots (last button of the list) to open the emulator settings.
On the settings screen (called "Extended controls"), select Microphone and turn on the option "Virtual microphone uses host audio input".
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.
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 :
. build/envsetup.sh
lunch 1
(ie. choose the generic option, not simulator)make -j<number>
wherenumber
= #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