I created a small go program that uses these go bindings to record some commands from the default microphone and act accordingly. It works fine as a standalone binary(both as normal user and root user) but when I tried to convert it into a systemd unit the Capture
function in the go bindings failed with error saying connection refused
.
The program is failing to capture the microphone input when running as a systemd service. The following is the unit file which is pretty much copy-pasted from here.
[Unit]
Description=Commander service providing voice commands
[Service]
ExecStart=/path/to/binary/binary.sh
[Install]
WantedBy=multi-user.target
binary.sh is a simple shell script that for providing environment variables to the go binary. The script is below
#!/bin/bash
cd /path/to/binary
env LD_LIBRARY_PATH=/usr/local/lib ./binary > stdout 2> stderr
The LD_LIBRARY_PATH
is needed for pocketsphinx
shared libraries which is being used for recognizing commands from audio.
I think something is wrong with the unit file but I don't know what it is. The whole project can be found here.
Any insight would be helpful. Thanks.