TransWikia.com

How can I run sox as a service?

Unix & Linux Asked on December 26, 2021

I want to run the following bash for recording speaker output as an mp3 file using sox as a service in background (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"

When I run the file in terminal, it prompts the following message and is listening for the input device:

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    

This is my service:

[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

However, it seems that it doesn’t wait for the speaker and exited, right. Just i see a blob data, which I don’t know what it is (?)…
please guide me how can I run such a bash as a service? Or if it’s not possible what is the best way to start it at boot or after user login…

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.

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