如何将 sox 作为服务运行?

如何将 sox 作为服务运行?

我想运行以下 bash 将扬声器输出记录为 mp3 文件,sox在后台用作服务(Ubuntu 20.04):

#!/bin/bash
echo "Monitoring sound card for recordings"
name="record"
name=/home/ahmad/recordings/$name
now="$(date +'%m-%d-%H-%M-%S')"
sox -v 5 -t pulseaudio alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -t mp3 "$name"-"$now".mp3 silence 1 0.1 3% 1 3.0 3%
echo "$name-$now was recorded"

当我在终端中运行该文件时,它会提示以下消息并正在侦听输入设备:

Monitoring sound card for recordings
Monitoring speaker sound v4

Input File     : 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor' (pulseaudio)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM
Level adjust   : 5 (linear gain)

In:0.00% 00:01:18.42 [00:00:00.00] Out:0     [      |      ]        Clip:0    

这是我的服务:

[Unit]
Description=Example systemd service.

[Service]
Type=simple
WorkingDirectory=/home/ahmad/recordings
ExecStart=/bin/bash /home/ahmad/recordings/myrec1 
User=ahmad

[Install]
WantedBy=multi-user.target

不过,好像没有等说话者就退出了,对吧。只是我看到一个 blob 数据,我不知道它是什么(?)...请指导我如何运行这样的 bash 作为服务?或者,如果不可能,在启动时或用户登录后启动它的最佳方法是什么......

14:33:58 app bash[10581]: Channels       : 2
جولای 24 14:33:58 app bash[10581]: Sample Rate    : 48000
جولای 24 14:33:58 app bash[10581]: Precision      : 16-bit
جولای 24 14:33:58 app bash[10581]: Sample Encoding: 16-bit Signed Integer PCM
جولای 24 14:33:58 app bash[10581]: Level adjust   : 5 (linear gain)
جولای 24 14:34:57 app bash[10581]: [15.1K blob data]
جولای 24 14:34:57 app bash[10581]: Aborted.
جولای 24 14:34:57 app bash[10561]: /home/ahmad/recordings/record-07-24-14-33-58 was recorded
جولای 24 14:34:57 app systemd[1]: myservice.service: Succeeded.

相关内容