Is there a way to record mic input in android while it is being process for playback/preview in real time? I tried to use AudioRecord and AudioTrack to do this but the problem is that my device cannot play the recorded audio file. Actually, any android player application cannot play the recorded audio file.
On the other hand, Using Media.Recorder to record generates a good recorded audio file that can be played by any player application. But the thing is that I cannot make a preview/palyback while recording the mic input in real time.
To record and play back audio in (almost) real time you can start a separate thread and use an
AudioRecordand anAudioTrack.Just be careful with feedback. If the speakers are turned up loud enough on your device, the feedback can get pretty nasty pretty fast.
EDIT
The audio is not really recording to a file. The
AudioRecordobject encodes the audio as 16 bit PCM data and places it in a buffer. Then theAudioTrackobject reads the data from that buffer and plays it through the speakers. There is no file on the SD card that you will be able to access later.You can’t read and write a file from the SD card at the same time to get playback/preview in real time, so you have to use buffers.