Search code examples
androidsqliteaudioaudio-recordingmicrophone

Android: possible directly microphone save to SQLite, without read / write a temporary file?


I have some sample code for how to record microphone input. As I understand, providing an output file is required:

    public void MediaRecorderReady(){
        mediaRecorder=new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
        mediaRecorder.setOutputFile(AudioSavePathInDevice);
    }

If that is true, I think there are some considerations, like the available memory (not knowing how much the recording will be, etc.).

Is it at all possible to make Android allocate memory, and record the microphone input -collecting bytes to a variable, and writing it as blob into db?

Also, would it be possible to use a conversion method to .wav when playing the blob field?


Solution

  • Using a BLOB to store audio could have limitations on the time due to the size of the resultant file. Let's say 300k per minute, then 20 around minutes and you'd reach the maximum that you'd be able to pull from the stored data due to A Cursor window having a limitation of 2mb. (you can store large BLOBS, you just can't retrieve them without having to resort to some custom means using the SQLite3 API's rather than utilising the inbuilt SQLiteDatabase routines).

    The recommended method for storing large data is to store the data as a normal file and to then store the path in the Database.

    Based upon Internal Versus External BLOBs in SQLite, BLOBS up to 100k can be saved more efficiently than when saving to a file system.

    You may also wish to consider 35% Faster Than The Filesystem.

    Regarding conversio to .wav this may be of interest JLayer project: MP3 decoder/player/converter library for Java™ platform.