Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created November 24, 2022 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplitza/dd7edce359bca87bfda6cd5330a826db to your computer and use it in GitHub Desktop.
Save jplitza/dd7edce359bca87bfda6cd5330a826db to your computer and use it in GitHub Desktop.
Make Wireplumber route Firefox' voice output to internal ALSA output
stream_defaults.rules = {
{
matches = {
{
{ "application.name", "matches", "Firefox" },
{ "media.name", "matches", "AudioCallbackDriver" },
{ "media.class", "matches", "Stream/Output/Audio" },
}
},
apply_properties = {
["target"] = "alsa_output.pci-0000_06_00.6.analog-stereo",
["state.save-target"] = false,
}
}
}

This makes Wireplumber (the new audio routing engine for Pipewire, used by default in Ubuntu 22.10) route all voice streams from Firefox, e.g. during video calls (identified by their media.name being "AudioCallbackDriver") to another sink than the default (e.g. your headphones).

  1. Copy the 41-firefox-callback.lua to ~/.config/wireplumber/main.lua.d/ and adapt the target value to your needs (pactl list sinks)
  2. Copy /usr/share/wireplumber/scripts/restore-stream.lua to ~/.config/wireplumber/scripts/restore-stream.lua
  3. Apply the restore-stream.lua.patch to that copy

The patch is neccessary because by default Wireplumber would ignore the target stream prop and always use the one from the file (~/.local/state/wireplumber/restore-stream). And even if it did use the stream prop, it would then save it to the restore-stream, but only matching Firefox and hence errornously redirecting e.g. music output from Firefox to your headphones, too.

--- /usr/share/wireplumber/scripts/restore-stream.lua 2022-10-04 15:25:09.000000000 +0200
+++ ~/.config/wireplumber/scripts/restore-stream.lua 2022-11-03 14:55:39.062548314 +0100
@@ -139,7 +139,7 @@
local stream_props = node.properties
rulesApplyProperties(stream_props)
- if stream_props["state.restore-target"] == false then
+ if stream_props["state.restore-target"] == false or stream_props["state.save-target"] == false then
return
end
@@ -353,7 +353,10 @@
end
if config_restore_target and stream_props["state.restore-target"] ~= false then
- local str = state_table[key_base .. ":target"]
+ local str = stream_props["target"]
+ if not str then
+ str = state_table[key_base .. ":target"]
+ end
if str then
restoreTarget(node, str)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment