我尝试创建一个在后台运行的服务,并在扬声器开始说话时记录其输出,并在扬声器停止时记录其输出。
为此,我创建了以下 bash,并且它可以按预期运行。
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
为了使其成为一项服务,我创建myrec
如下/etc/init.d/
内容:
#! /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
重新启动后,我希望它能够自动运行,当我通过检查其状态时sudo service myrec status
,它显示:
● myrec.service - LSB: your description here
Loaded: loaded (/etc/init.d/myrec; generated)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
所以我启动了它sudo service myrec start
,现在的状态是:
● 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.
我不知道它是否正在运行,但是当我播放并停止某些内容时,它不会在指定的文件夹中记录任何内容。
您能告诉我哪里出了问题吗?顺便说一句,如果有具有相同功能的工具,您可以介绍给我...
更新:
请注意,录音服务需要pulseaudio
运行服务,如果它不是系统范围的服务,则它不会在启动时运行,并可能导致上述问题