TransWikia.com

sox FAIL formats: can't open input `alsa_output.pci-0000_00_1b.0.analog-stereo.monitor': can not open audio device: Connection refused

Unix & Linux Asked on December 15, 2021

I wrote the following service to listen to the audio input:

[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

if I run the sox command in the terminal, everything is fine and it’s listening to the audio. However, if I start the service and check it’s status it says:

    ● 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'.

UPDATE

I noticed that if I run the command with sudo in terminal, I get the same error, so there must be some problem with permissions, or pulseaudio settings..

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

One Answer

The problem is that the pulseaudio isn't run system-wide so the pulseaudio service isn't run at boot.

It's not recommended to run it as systemwide in Desktop. However, ff you really want to do that refer to:

Pulseaudio as system-wide systemd service

Answered by Ahmad on December 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP