arecord: Create large (7 days) audio recording
For a scientific experiment, we're trying to create a large (7 day) audio recording using arecord
from alsa on a RasPi using a USB microphone. The pipeline for the recording is as follows:
arecord -f S16_LE -r16000 -d 259200 -D sysdefault:CARD=1 | gzip > test.wav.gz
When recording like this, the recording reproducibly ends after exactly 18h 38m 28s. This is probably related to the maximum wav file size of 2 GB that the --max-file-time
parameter talks about in the man page, as the file of the uncompressed wav file is almost exactly 2 GB at that point.
As we need to pipe the audio data into gzip (and, at a later stage, GPG) without saving it to disk first, we cannot use the automated file splitting offered by ALSA to get around this (at least we are not aware of any method to combine this with pipes). Is there any way to get around this issue in a way where the following conditions are met:
- There is no gap in the recording (stopping and restarting the recording would not work for us, as we need one continuous 7 day recording without any gaps).
- Ideally, the resulting format should still be .wav (or at least something similarily lossless).
- The file size should not increase too much (we need ~16k sampling rate, mono sound, and we have roughly 20 GB of space available).
- The whole thing should run on a RasPi3 that is also doing some other things (i.e. should not take too many system resources).
At the moment, we are considering recording into a raw data format and later re-encoding to wav on another machine, or re-encoding to FLAC on the fly, but any simpler solution would be appreciated.
Solution 1:
In the end, I ended up using the "encode to flac" solution. Here's the command chain I used:
arecord -t raw -f S16_LE -r16000 -d 604800 -D sysdefault:CARD=1 | flac - -f --endian little --sign signed --channels 1 --bps 16 --sample-rate 16000 -s -c | gzip > test.flac.gz
(Customize arecord and flac commands to your needs)
Note that I am piping to stdout and gzipping the whole thing right now - this is due to a special requirement that you may not have. If you want to skip that step, replace the -c
with a -o filename.flac
. This will also get rid of some problems the stdout version may cause.