Android:AudioCapture
The Android multimedia framework includes support for capturing and encoding a variety of common audio formats, so that you can easily integrate audio into your applications. You can record audio using the MediaRecorder APIs if supported by the device hardware. This document shows you how to write an application that captures audio from a device microphone, save the audio and play it back.
Performing Audio Capture
Audio capture from the device is a bit more complicated than audio and video playback, but still fairly simple:
- Create a new instance of android.media.MediaRecorder.
- Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC.
- Set output file format using MediaRecorder.setOutputFormat().
- Set output file name using MediaRecorder.setOutputFile().
- Set the audio encoder using MediaRecorder.setAudioEncoder().
- Call MediaRecorder.prepare() on the MediaRecorder instance.
- To start audio capture, call MediaRecorder.start().
- To stop audio capture, call MediaRecorder.stop().
- When you are done with the MediaRecorder instance, call MediaRecorder.release() on it. Calling MediaRecorder.release() is always recommended to free the resource immediately.
안드로이드에서 오디로를 녹음하는 세 가지 방법 (THE THREE MUSKETEERS OF AUDIO RECORDING FROM ANDROID)
Let me introduce you to the three musketeers of audio recording from android os. They are the three ways for recording audio in android. They are
#1. MediaRecorder
- API Documentation: http://developer.android.com/reference/android/media/MediaRecorder.html
- USAGE: http://developer.android.com/guide/topics/media/index.html
MediaRecorder does what it says. It records media. It can be used to record audio from Mic to a file on the sdcard. The recorded audio would be in MPEG4, RAW AMR or 3GP.
Please note: The example provided along with the documentation does not work. However, there are lots of help on the internet to get the mediarecorder running.
- pros:
- easy to use.
- records audio in compressed format.
- can be used to record voice calls - both uplink and downlink.
- can be used to record speech recognition.
- can not access the audio buffers.
- difficult to process the recorded audio as it would be compresses format.
- can not change the sampling rate.
- very little or no control of how the recording happens.
#2. AudioRecord
- API Documentation: http://developer.android.com/reference/android/media/AudioRecord.html
- USAGE: http://hashspeaks.wordpress.com/2009/06/18/audiorecord-part-4/
AudioRecord API is google's official solution to overcome the limitations of mediarecorder.Audio can be recorded into buffers for post processing. Audiorecord is a java way to record audio and process audio.
- pros:
- records audio as MONO or STEREO
- various properties for audiorecording like sample size, sample rate, buffersize can be set.
- the recorded audio is provided in buffers.
- difficult to handle buffers. Unless you know what you are doing. you will lose samples.
#3. Audiorecord (native interface)
- A LITTLE BIT HELP: http://hashspeaks.wordpress.com/2009/04/18/audiorecord-in-android-part-2/
There is also a native interface - audiorecord that can be used for recording audio. The native interface provides API that can be invoked from c/c++ libraries. These librarires can then be called from Java activity via JNI. Programs using the interface can be compiled with the NDK and used in android applications via JNI.
- pros:
- provides a c/c++ interface to recording
- the processing is more efficient when done in c/c++ using this API
- no documentation is available for this interface
- google does not official support this interface.
- This interface could be removed from future releases without further notification. But has remained for over an year now.
See also
- android.media.MediaRecorder
- android.media.MediaRecorder.AudioSource
- Android:AudioRecord
- android.media.AudioTrack
- android.media.AudioTrack:PcmTest (Example)