# Can you recommend an efficient encoding algorithm for sound with long periods of silence?

As a side personal project, I'm coding an Android application that I plan to use to record the sounds of our first baby. I'm kind of new to the world of Android development and sound processing, so please bear with me if this question is naive :)

What I'm trying to do is to constantly save the sounds in our baby room, splitting the recordings in 2-hour intervals. I plan to keep this data for future analysis (e.g. plotting crying times, which I'll correlate with other events, and maybe cry identification).

So far the application is working fine. However, I wonder if there is an efficient codec I can use considering that 90% of the time there will be silence. I've tried modifying the PCM raw data before enters the codec setting to zero any values below a specific threshold, but this did not reduce the file size substantially. This was a wild guess, just in case this would "help" the codec (I've tried AAC/HE and MP3, not yet AMR).

Can you please point me in the right direction?...

I don't mind using a solution that requires post processing of the files. For example, I've looked into http://sox.sourceforge.net, but that strips silence periods reducing the recording length (I want to keep the timestamps and length untouched).

Note: using SoX to split the file in parts using a naming scheme that allows me to reconstitute original times it's an option... but I could not come with that script, yet).

Bonus question: will AMR-NB be enough to encode a baby cry, if I want to run some processing later? (for example this or this) or... should I stick to AMR-WB?

Thank you,

Update July 22nd:

Thanks everyone for the responses so far. The idea of using just WAV injecting zeros, and later using bzip2, etc. to compress the repetitive data is really good (thanks @MBaz).

@Fat32: I've erased the files, but I recall sizes around ~20Mb/hr, with no substantial change after replacing low PCM values (approximately 50% of the stream) with zeros.

Another update: AMR-WB is giving me better results than AAC/HE, ~6 Mb/hr. So I'll probably stick to it, however I'm not sure how the low bitrate + sampling rate will affect things if later I decide to run some infant identification analysis later (i.e. if the loss of information will remove data points crucial for the neural net).

• Traditional entropy encoders such as gzip and bzip2 are very good at compressing repetitive data. Have you tried gzipping the raw PCM? One great benefit would be that you'd have lossless compression. If there is low-level random noise in the PCM, you may try thresholding the data before compression.
– MBaz
Jul 20, 2017 at 14:32
• This is a very good and creative idea, thanks! Jul 22, 2017 at 0:47

Thresholding should reduce the file size to the limits of the encoder being used. AAC/H.264 are using the state of the art general purpose audio compression codecs (which could only be beaten by application specific optimized codecs, such as speech vocoders etc).

May be your files are already minimal? Put some numerical data such as the sampling rate, average bits per sample, recording duration and file sizes...

If I were so inclined to do what you want to do( I have 3 children, youngest is 25 , so I'm not so inclined) , I would use a motion detector to trigger recording for the first few months. Crying is usually accompanied with vigorous hand and arm motion.

There are a number of wifi video cameras with integrated motion detectors and microphones, as well as web based api's.

The most typical situation for a young couple is to be extremely sleep deprived for the first few months. You might want to take a minimal effort approach.

You might try using some sort of activity detector algorithm, and just not feed the codec any data (not even zeros) when no activity was detected. For the time stamps, you might prepend recorded activity with an FSK time mark and/or voice synthesized time announcement, and feed that to the codec in front of the captured audio samples.

You should get rather good results with using both a) a hard noise gate (so that the material compresses perfectly when you are having silence) b) a variable bit rate recording: MP3 as well as OGG/Vorbis encoders can readily provide those.

When you are planning on eventually analyzing breathing patterns, of course the noise gate will either not be effective or ruin your data.

But option b) should also help a bit when used alone.