Skip to content

Start automatically with Systemd

lawl edited this page Feb 14, 2022 · 7 revisions

Note: This is not recommended, as NoiseTorch will always use some CPU even when not in use. See this upstream PulseAudio issue. This may not be an issue with PipeWire. Use at your own risk.


Find Systemd device unit

First, you'll need to find the Systemd unit corresponding to your microphone. We will use this to prevent the NoiseTorch service from loading before the mic becomes available.

Run systemctl list-units --type=device and find the name of the unit file for your microphone:

List of units

On this system, the device unit is sys-devices-pci0000:00-0000:00:01.3-0000:02:00.0-usb1-1\x2d6-1\x2d6:1.0-sound-card2.device.

Find NoiseTorch device name

Next, NoiseTorch needs to know what microphone source to use as an input.

Run noisetorch -l and find the device id of your microphone:

List of DeviceIDs

On this system, the device id is alsa_input.usb-0c76_USB_PnP_Audio_Device-00.mono-fallback.

Create Systemd Unit

Finally, create a Systemd user unit with the sink name and unit found earlier.

Put the following content in ~/.config/systemd/user/noisetorch.service:

[Unit]
Description=Noisetorch Noise Cancelling
Requires=$DEVICEUNIT
After=$DEVICEUNIT
# Depending on if you're using pulseaudio or pipewire, uncomment the correct line
# After=pulseaudio.service
# After=pipewire.service

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=%h/.local/bin/noisetorch -i -s $DEVICEID -t 95
ExecStop=%h/.local/bin/noisetorch -u
Restart=on-failure
RestartSec=3

[Install]
WantedBy=default.target

Replace $DEVICEUNIT and $DEVICEID with the info found in the previous steps. Uncomment the correct After target, for pipewire or pulseaudio, depending on which one you're using.

Reload systemd so it picks up the new service: systemctl --user daemon-reload

Start and enable the service: systemctl --user start noisetorch && systemctl --user enable noisetorch

This guide was originally provided by @detjensrobert. If you're opening an issue regarding anything with this guide, make sure to tag @detjensrobert in issues or you're unlikely to receive any help.