Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Apr 2020 09:06:35 +0100
From:      Steve O'Hara-Smith <>
To:        Polytropon <>
Cc:        FreeBSD Questions <>
Subject:   Re: Audio recording on demand (level + duration)
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Thu, 23 Apr 2020 17:51:26 +0200
Polytropon <> 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 <>

Want to link to this message? Use this URL: <>