# Listener

First install libsndfile!
Then:

    make install

Then run 'setlistener' with as parameter the device to listen to.

    setlistener /dev/dsp

Then, with the left and right arrow keys, move the '|' until the word "" appears. No, don't you move the '|' to the maximum right, move it to the right until the "" just constantly appears. Then: remember the value "Current level: ".
Next step is creating the file /usr/local/etc/listener.conf Copy the example listener.conf to the location mentioned above and edit it to suit your needs.
For example:

    wav_path = /home/folkert/recordings
    detect_level = 800
    min_duration = 1
    max_duration = 300
    rec_silence = 5
    audio_parameters = 44.1khz,1,wav,pcm16
    from_pipe = 0
    exec = /home/folkert/encode_sample
    prerecord_n_seconds = 3

## audio_parameters

Format sets what kind of outputfile is generated AND how the sound is recorded.
Run listener with -h to get a list of parameters.
In any order you can set the samplerate (e.g. 44100 or 22.05khz), the number of channels, the output-file-type, the file subtype (e.g. 16 bit or adpcm compressed).

## rec_silence

When while recording things become silent, don't stop recording immediately but keep recording for 'rec_silence' seconds to see if the sound restarts.

## min_duration

When the sound starts, record at least that many seconds of audio, measured relative to the start of the recoding.
E.g. if the sound only sounds for 3 seconds and you've set this value to 5, still at least 5 seconds of audio will be recorded.

## min_triggers

sets how many samples must be above the threshold (the 'detect_level') before recording starts. The samplerate is set to 44.1kHz so if you set min_duration to 4410, the minimum length (duration) of sound before the recording starts is: 0.1s (or: one tenth of a second).

## max_duration

How long a sample may be before a new file is started.

## one_shot

When set to yes/on/1, listener will exit after the first recorded sample.

## prerecord_n_seconds

How many seconds to record before the sound starts.

## from_pipe

sets wether listener is reading from a pipe fed by listenersoundpipe. listenersoundpipe lets you split a sound- device in two so that you can check 2 rooms with only one sound- card. You need to create two pipes and start 2 listener processes, each reading from one pipe.
Set this parameter to yes/on/1 for "pipe-mode", no/off/0 for normal mode.

## exec

selects the script/program to execute after the sample was recorded. This first (and only) parameter for that script is the filename of the sample.

## on_event_start

selects the script/program to execute before the sample was recorded.

## output_pipe

Instead of writing to a wav-file, listener can also execute an external program which does the compression and/or file-I/O.
e.g.:

    output_pipe=bladeenc -rawstereo -rawsigned -rawchannels=2 STDIN /tmp/my_file.mp3

## filter

lets you add one or more filters. these will be used when detecting sounds. beware: sound is written to the wav-files BEFORE the filtering is done. See the directory 'filter_lib_example' for an example on how to write a filter for listener.

## amplify

Wether to automatically amplify the sound or not. Use 'on' and 'off' to toggle.

## start_amplify

What amplification to use when the sound starts. This will be adjusted to something more applicable UNLESS 'fixed_amplify' is set to yes.

## max_amplify

Maximum amplification to use.

## fixed_amplify

Wether to ONLY use the amplification factor set with 'start_amplify' (=yes) or let listener do autotuning (=no).
safe_after_filtersets wether to save the audio-data to disk before or after the filtering. Before the filtering gives you the original sound while after gives you the sound after processing with the filter(s).
Enter 'on' or 'off'.
The final step is starting the program:

    listener

and that's it!
Thanks to Hugo Hugo for adding code that enables you to set some parameters from the commandline.
If you have any suggestions or anything else, do not hesitate to contact me at the following e-mail address:
folkert@vanheusden.com