Thursday, June 16, 2011

Tutorial: Accessing Microphone on Android in Adobe AIR


This video is the latest in a long series of tutorials on how to use the new Flash Builder for Flex Mobile Development.  This particular exercise targets Android however the same code can be run on iOS (cross compiled using 4.5.1) and BlackBerry Tablet OS.  Here is the video:



The project will be released shortly to the Android marketplace along with the full source code and some great new graphics thanks to my brother Paul Trani!  If you want the project source code for Flash Builder 4.5.1 + in the meantime, please email me direct dnickull at adobe dot com.

This will be part of the AIR Mobile Code Camp at Adobe MAX 2011 in October!  Sign up now!

10 comments:

  1. This video and the source code have been really helpful to me. One thing missing is what to do with the audio in the ByteArray once it has been created. I would really like to be able to store the data somehow to the mobile device. I see some people are using the WavEncoder library to convert the ByteArray to a WAV file. There are plenty of native iOS voice recorders that save as mp3 files. Is there any good way to compress the data for local storage?

    Thanks,
    Adrian

    ReplyDelete
  2. Yes there is. Christoph Coenraets first made one which I can share the source with you. Mine is writing floats instead of bytes so it has a small bug right now. Michael Chaize extended this idea and used the MP3 compression. The article is here:

    http://www.riagora.com/2010/08/air-android-and-the-microphone/

    Duane

    ReplyDelete
  3. Thanks Duane. I saw that post, and Christoph says that the mp3 compression is quite slow. Seeing as Corona has the ability to save recordings as mp3 and iOS natively supports compressing with AAC, I was hoping there was a similar solution in Flash. But maybe I just need to try out Christoph's solution and see if it works for my needs.

    Cheers,
    Adrian

    ReplyDelete
  4. Can you send me your email to dnickull at adobe dot com and I will send you the latest I have. it "almost" works.

    ReplyDelete
  5. hey Duane

    my simple mobile record-playback microphone audio app works great on android but on ios a half of second or so of audio is missing from the beginning of the recording (i guess the recording starts late)

    have you tried your code with ios?

    thanx
    Saar

    ReplyDelete
  6. hello Duane

    any success running this code on ios?

    thanx
    Saar

    ReplyDelete
  7. yes - it runs on iOS but you need to ensure the project is set to compile into the native machine code and also get an Apple developer certificate and provisioning file.

    Duane

    ReplyDelete
  8. Hi Duane,

    Thank you for a wonderful insight into accessing the microphone on android. Both capture and play back are working fine. On some of the android devices when I am using full duplex, the capture audio from the speaker is getting clipped and distorted. When nearend audio is getting captured that time captured audio is coming fine. To avoid the clipping I tried with reducing the speaker level, the audio level is not audible. So I want to reduce the microphone level, how to do this. Any insight into this will be greatful.

    Thanking you,
    ksam

    ReplyDelete
  9. Hi Duane,

    Thank you for a wonderful insight into accessing the microphone on android. Both capture and play back are working fine. On some of the android devices when I am using full duplex, the capture audio from the speaker is getting clipped and distorted. When nearend audio is getting captured that time captured audio is coming fine. To avoid the clipping I tried with reducing the speaker level, the audio level is not audible. So I want to reduce the microphone level, how to do this. Any insight into this will be greatful.

    Thanking you,
    ksam

    ReplyDelete
  10. You can control the gain on the raw microphone itself. Set up your microphone variable, then give the gain property a value between 0 and 100, 0 being complete mute.

    private var mic:Microphone;
    mic.gain = 43;

    I usually tie the gain to a slider control to give the recorder the ability to adjust this for a device. You would want an audio meter showing signal strength then set the signal to around -6 to -12 db. This takes a bit of audio engineering.

    Duane

    ReplyDelete

Do not spam this blog! Google and Yahoo DO NOT follow comment links for SEO. If you post an unrelated link advertising a company or service, you will be reported immediately for spam and your link deleted within 30 minutes. If you want to sponsor a post, please let us know by reaching out to duane dot nickull at gmail dot com.