![sox 失败格式:无法打开输入“alsa_output.pci-0000_00_1b.0.analog-stereo.monitor”:无法打开音频设备:连接被拒绝](https://linux22.com/image/177449/sox%20%E5%A4%B1%E8%B4%A5%E6%A0%BC%E5%BC%8F%EF%BC%9A%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%E8%BE%93%E5%85%A5%E2%80%9Calsa_output.pci-0000_00_1b.0.analog-stereo.monitor%E2%80%9D%EF%BC%9A%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%E9%9F%B3%E9%A2%91%E8%AE%BE%E5%A4%87%EF%BC%9A%E8%BF%9E%E6%8E%A5%E8%A2%AB%E6%8B%92%E7%BB%9D.png)
我编写了以下服务来监听音频输入:
[Unit]
Description=Monitor Audio Output
After=syslog.target network.target plusaudio.service
[Service]
Type=simple
ExecStart=sox -v 5 -t pulseaudio alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -t mp3 /home/ahmad/recordings/k2.mp3 silence 1 0.1 3% 1 3.0 3%
Restart=on-success
EnvironmentFile=/etc/environment
User=ahmad
[Install]
WantedBy=default.target
如果我sox
在终端中运行命令,一切都很好并且它正在收听音频。但是,如果我启动该服务并检查其状态,它会显示:
● runsox.service - Monitor Audio Output
Loaded: loaded (/etc/systemd/system/runsox.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2020-07-23 21:06:28 +0430; 43s ago
Process: 5517 ExecStart=/usr/bin/sox -v 5 -t pulseaudio alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -t mp3 /home/ahmad/recordings/k2.mp3 silence 1 0.1 3% 1 3.0 3% (code=exited, status=2)
Main PID: 5517 (code=exited, status=2)
جولای 23 21:06:27 app systemd[1]: Started Monitor Audio Output.
جولای 23 21:06:28 app sox[5517]: /usr/bin/sox FAIL formats: can't open input `alsa_output.pci-0000_00_1b.0.analog-stereo.monitor': can not open audio device: Connection refused
جولای 23 21:06:28 app systemd[1]: runsox.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
جولای 23 21:06:28 app systemd[1]: runsox.service: Failed with result 'exit-code'.
更新
我注意到,如果我在终端中运行命令sudo
,我会得到同样的错误,所以权限或脉冲设置一定有问题。
sudo /usr/bin/sox -v 5 -t pulseaudio alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -t mp3 /home/ahmad/recordings/k2.mp3 silence 1 0.1 3% 1 3.0 3%
/usr/bin/sox FAIL formats: can't open input `alsa_output.pci-0000_00_1b.0.analog-stereo.monitor': can not open audio device: Connection refused
答案1
问题是pulseaudio 不是在系统范围内运行,因此pulseaudio 服务不会在启动时运行。
不建议在桌面系统范围内运行它。但是,如果您确实想这样做,请参阅: