Audio recording on demand (level + duration)

Steve O'Hara-Smith steve at sohara.org
Fri Apr 24 08:06:45 UTC 2020


On Thu, 23 Apr 2020 17:51:26 +0200
Polytropon <freebsd at edvax.de> wrote:

> My question is:
> 
> What file can I monitor (and how) to obtain an information
> about _if_ there is some audio input? I'd probably use the
> rec command from the sox package for recording, and probably
> something like lame for MP3 conversion.

	Use sox it has no trouble encoding to mp3 in real time (or flac
which is my preferred recording format) and can be told to skip leading
silence - I use it like this to create timestamped recordings without
leading silence.

NOW=`date -Iseconds | cut -c12-19`
rec $NOW.flac silence 1 0.5 0.1%

	You could start with that and watch for the file to start growing
to see when sound starts.

	But sox is cleverer than that - viz this extract from man sox:

          rec -r 44100 -b 16 -e signed-integer -p \
            silence 1 0.50 0.1% 1 10:00 0.1% | \
            sox -p song.ogg silence 1 0.50 0.1% 1 2.0 0.1% : \
            newfile : restart

       records a stream of audio such as LP/cassette and splits in to
multiple audio files at points with 2 seconds of silence.   Also,  it
does  not start  recording  until  it detects audio is playing and stops
after it sees 10 minutes of silence.

	I suspect you can torture sox into doing pretty much what you want
but you'll have to wrap your head round the silence and newfile options :)

-- 
Steve O'Hara-Smith <steve at sohara.org>


More information about the freebsd-questions mailing list