Skip to content

Instantly share code, notes, and snippets.

@oasido
Forked from amazingidiot/README.md
Created November 9, 2022 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oasido/7b12edcf8fc1fb8dbfbbe610904b3e25 to your computer and use it in GitHub Desktop.
Save oasido/7b12edcf8fc1fb8dbfbbe610904b3e25 to your computer and use it in GitHub Desktop.
Pipewire virtual devices as systemd user services

Create pipewire virtual devices as systemd user services

Add both files to ~/.config/systemd/user/ and enable them via systemctl --user enable --now pipewire-source-stereo@sourcename.service or systemctl --user enable --now pipewire-sink-stereo@sinkname.service. Change sourcename and sinkname in the command to your needs. You can add multiple devices with different names.

[Unit]
Description = Add a pipewire stereo sink named %i
After = pipewire.service
[Service]
Type = oneshot
StandardOutput = journal
ExecStart = /bin/sh -c 'pactl load-module module-null-sink media.class=Audio/Sink sink_name="%i" channel_map=stereo > %h/.cache/pipewire_sink_stereo_%i'
ExecStopPost = -/bin/sh -c 'pactl unload-module $(cat %h/.cache/pipewire_sink_stereo_%i)'
ExecStopPost = -/bin/rm %h/.cache/pipewire_sink_stereo_%i
RemainAfterExit = true
[Install]
WantedBy = default.target
[Unit]
Description = Add a pipewire stereo source named %i
After = pipewire.service
[Service]
Type = oneshot
StandardOutput = journal
ExecStart = /bin/sh -c 'pactl load-module module-null-sink object.linger=1 media.class=Audio/Source/Virtual sink_name="%i" channel_map=stereo > %h/.cache/pipewire_source_stereo_%i'
ExecStopPost = -/bin/sh -c 'pactl unload-module $(cat %h/.cache/pipewire_source_stereo_%i)'
ExecStopPost = -/bin/rm %h/.cache/pipewire_source_stereo_%i
RemainAfterExit = true
[Install]
WantedBy = default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment