3

I try to create a service that runs in background and record the output of speaker whenever it starts to speak and stops when it stops.

I created the following bash for this purpose and it works as expected.

echo "Monitoring sound card for recordings"
name="record"
name=~/recordings/$name
while true 
do
        echo "Monitoring speaker sound "
        now="$(date +'%m-%d-%H-%M-%S')"
        parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | sox -v 5 -t raw -b 16 -e signed -c 2 -r 44100 - "$name"-"$now".ogg silence 1 0.1 3% 1 3.0 3%

        #test $? -eq 0 && break;
        echo "$name-$now was recorded"
done

To make it a service I created myrec in /etc/init.d/ as follows:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          myrec
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: your description here
### END INIT INFO

PATH=/home/ahmad/recordings
DESC="Recording audio output"
NAME=myrec
DAEMON=/home/ahmad/recordings/myrec.sh
DAEMON_ARGS="s read"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

After rebooting I expected it to run automatically, when I checked its status via sudo service myrec status, it shows:

● myrec.service - LSB: your description here
     Loaded: loaded (/etc/init.d/myrec; generated)
     Active: inactive (dead)
       Docs: man:systemd-sysv-generator(8)

So I started it by sudo service myrec start and now the status is:

● myrec.service - LSB: your description here
     Loaded: loaded (/etc/init.d/myrec; generated)
     Active: active (exited) since Wed 2020-07-22 15:23:24 +0430; 4s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 3714 ExecStart=/etc/init.d/myrec start (code=exited, status=0/SUCCESS)

جولای 22 15:23:24 app systemd[1]: Starting LSB: your description here...
جولای 22 15:23:24 app systemd[1]: Started LSB: your description here.

I don't know if it's running or not but when I play and stop somethings, it doesn't record anything in the specified folder.

Could you guide me what is wrong? By the way if there is a tool with the same functionality you may introduce that to me...

Update:

Please note that recording service requires pulseaudio service to be run and if it's not a system-wide service, it isn't run at start and can cause the problem above

3
  • Does this tool have to run in background? Audacity won't do?
    – GunJack
    Aug 11, 2020 at 8:03
  • are you sure the monitor device is correct
    – GunJack
    Aug 11, 2020 at 8:10
  • @GunJack Please note that recording service requires pulseaudio service to be run and if it's not a system-wide service, it isn't run at start and can cause the problem above
    – Ahmad
    Aug 11, 2020 at 8:34

0

You must log in to answer this question.

Browse other questions tagged .