简体   繁体   中英

Android emulator audio input capturing

I want to develop an android app that captures the audio in it's surroundings (like a recorder would do, not just the users voice but any audio). Therefor, I am looking for a way to test this app using an android emulator (ANY free android emulator).

I found a lot of question but no real answers on this subject:

Android's Audio Capture documentation tells me it's impossible:

Note: The Android Emulator does not have the ability to capture audio, but actual devices are likely to provide these capabilities.

The answer to this SO question tells me it is possible via some AVD configurations:

You need to add audio recording + playback support to the emulator (Android SDK and AVD manager -> Virtual devices -> Edit -> Hardware -> New).

but I have no idea where to find these "Virtual devices -> ..." menu options (or whatever they are), I even think they no longer exist in the current AVD manager and SDK manager.


This answer on SO tells me it is possible but only when using a very specific AudioRecorder configuration.

All of these suggestions seem to be from at least 2 years ago, so I guess they're not up-to-date. I know I could use a real device but don't have one at the moment, and that would only cover the app's behaviour on one version of android on one specific device. I really need more testing than that.

Is it possible to test and debug audio-capturing apps on an emulator AT ALL?
Is there a way to capture audio input on an emulator (maybe using an other emulator than the standard one?) ?
Can I somehow forward the input from microphone connected to my PC or from my speakers or directly from an audio file (mp3 for eg.)?

I am using windows 8.1 and Android studio 1.2.2

Yes, it is possible. All it needs just to start recording using AudioRecord (or whatever), but in some cases (depended on system image used in emulator) recording could be performed only in 8000 samples per second.

For example, when I'm using Lollipop images for emulator, it is possible to record on declared rate (44100), although it sounding like if it resampled. When using Kitkat or lower images, it is only possible to record ad 8000sps.

Like the other guy said, it is possible. As of Android Studio 2.2.3, you don't need any of the information listed above. It should just work... assuming you match the setup I'm using. The setup I'm currently using:

  • Ubuntu 16.04
  • OpenSL ES
  • Emulator Settings
    • KVM
    • Google APIs
    • Nexus 6P hardware profile
    • Working and tested API Versions
      • 23
      • 24

This is how I'm instantiating the OpenSL ES playback instance:

  // Set-up audio source.
  SLDataLocator_AndroidSimpleBufferQueue lDataLocatorIn = {
    SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, BUFFER_COUNT
  };
  SLDataFormat_PCM lDataFormat = {
    SL_DATAFORMAT_PCM,
    1, // numChannels
    SL_SAMPLINGRATE_11_025 / 1000, // sample rate here
    SL_PCMSAMPLEFORMAT_FIXED_16, // bitsPerSample
    16, // containerSize
    SL_SPEAKER_FRONT_CENTER, // channelMask
    SL_BYTEORDER_LITTLEENDIAN
  };
  SLDataSource lDataSource = { &lDataLocatorIn, &lDataFormat };

  SLDataLocator_OutputMix lDataLocatorOut = {
    SL_DATALOCATOR_OUTPUTMIX,
    outputObj_
  };
  SLDataSink lDataSink = {
    &lDataLocatorOut,
    NULL
  };

For some reason, the API 25 emulator doesn't support the 11025 sample rate (errors with a status -22.... this log line is happening in AudioRecord which is another Android API which I'm not directly using). I can't even begin to understand why as I just got this working recently, but I'm currently investigating it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM