Android: Voice Recording and saving audio

There is an example of how to do audio capture using MediaRecorder in the Android Developer Documentation.

I would recommend saving the files on the SD Card and then have your gallery code check the SD card to see which files to display. You can get the directory of the SD Card using the Environment.getExternalStorageDirectory() method. It would be best to save your files in a subdirectory of the SD Card root directory.

Make sure you give your applications the Permissions it will need. At the very least it will need RECORD_AUDIO and WRITE_EXTERNAL_STORAGE.

Also you have to see these tutorials:

http://www.androiddevblog.net/android/android-audio-recording-part-1

http://www.androiddevblog.net/android/android-audio-recording-part-2


If you really want to record audio via the speech recognition API then you could use the RecognitionService.Callback which has a method

void bufferReceived(byte[] buffer)

This gives you access to the recorded audio buffer as speech is being recorded and recognized. (No information is provided about the sample rate though.) You can then save the obtained buffers into a file for a later playback. I think keyboard apps use this call to display the waveform of the recorded speech. You have to implement the UI yourself.

The bare RecognizerIntent.ACTION_RECOGNIZE_SPEECH just returns a set of words/phrases without any audio.