Search code examples
androidmediarecorderandroid-mediarecorder

record audio but save it if it has data on android


I am recording audio on android but the main issue I am facing right now is that I don't want to save audio file if audio has no data in it (like the user has said nothing). I can save it then check the time or length of the audio file and then delete it, but I want to check it before storing file to reduce the work and improve performance.


Solution

  • Depending on ambient noise, checking the amplitude may not be enough. You may need to do a Fast Fourrier transform on the audio to separate the frequencies. This can be done with a minimal amount of buffering.

    See video for a visual explanation of what a Fourrier Transform is. There is also this video. It's actually a super fascinating topic.

    In any case, there is sample code for an audio visualizer in the following book. Here is the accompanying github site for that book. It may also contain some other audio-related code samples you may find useful.