{"id":47308,"date":"2024-10-01T14:14:56","date_gmt":"2024-10-01T14:14:56","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47308"},"modified":"2024-10-01T14:14:56","modified_gmt":"2024-10-01T14:14:56","slug":"configure-audio-wireplumber-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/10\/configure-audio-wireplumber-ubuntu-24-04\/","title":{"rendered":"Configure Audio Input\/Output via WirePlumber in Ubuntu 24.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-38513\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/04\/audio-recorder-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>As you know, Ubuntu uses PipeWire as replacement of PulseAudio for its default sound server since Ubuntu 23.04. And, it now uses WirePlumber to manage pipewire session and policy.<\/p>\n<p>With <a href=\"https:\/\/pipewire.pages.freedesktop.org\/wireplumber\/\" target=\"_blank\" rel=\"noopener\">WirePlumber<\/a>, you may configure more about your sound output and input. You can use Linux command to switch default audio input\/output device, change volume level, and mute\/un-mute sound and microphone.<\/p>\n<p>As well, you may change the audio bit depth, sample rate, resample quality, and other properties for certain sound device.<\/p>\n<p><!--more--><\/p>\n<p><b>NOTE: This tutorial does NOT work for Ubuntu 22.04 and earlier, since they use PulseAudio as default. And, lua script does NOT work for 24.10 &amp; later due to policy change!<\/b><\/p>\n<h3>Use wpctl Command<\/h3>\n<p>WirePlumber has a command line tool called <code>wpctl<\/code>. It&#8217;s useful for getting your device status, properties, and change some settings on the fly, such as set default audio device and change volume.<\/p>\n<p>First, open up a terminal window (<code>Ctrl+Alt+T<\/code>) and run command:<\/p>\n<pre>wpctl status<\/pre>\n<p>The command will output all the audio devices, audio sinks, and audio sources. The ones with <b>*<\/b> at the beginning are the defaults that in use. And, the numbers (e.g., 48, 49, 39 in the screenshot below) are the IDs.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47309\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status-700x452.webp\" alt=\"\" width=\"610\" height=\"394\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status-700x452.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status-300x194.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status-768x496.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wp-status.webp 946w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>To switch default audio input or output device<\/b>, if you have multiple devices available, then use command:<\/p>\n<pre>wpctl set-default ID<\/pre>\n<p>Here replace the ID with the number you got from the last <code>wpctl status<\/code> command.<\/p>\n<p>And, you may use the commands below to increase, decrease, or set volume. Which can be useful for scripting purpose or binding for keyboard shortcuts.<\/p>\n<ul>\n<li><b>Increase volume<\/b> by 5% for default audio output, with a limit of 150%:\n<pre>wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+<\/pre>\n<\/li>\n<li><b>Decrease volume<\/b> by 5% for default audio output:\n<pre>wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-<\/pre>\n<\/li>\n<li><b>Set volume<\/b> of default output to 0.5:\n<pre>wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.5<\/pre>\n<\/li>\n<li><b>Toggle mute\/unmute<\/b> for default audio output (or replace <code>toggle<\/code> with <code>0<\/code> to unmute or <code>1<\/code> to mute):\n<pre>wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle<\/pre>\n<\/li>\n<\/ul>\n<p>In the commands above, you may replace <code>@DEFAULT_AUDIO_SINK@<\/code> with <code>@DEFAULT_AUDIO_SOURCE@<\/code> for the default audio input (e.g., microphone). Or use ID number instead for certain audio sink\/source.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-volumecontrol.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47310\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-volumecontrol-700x309.webp\" alt=\"\" width=\"610\" height=\"269\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-volumecontrol-700x309.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-volumecontrol-300x133.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-volumecontrol.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Use lua script to configure Sound Properties<\/h3>\n<p><b>NOTE: This step only works for WirePlumber 0.4.x (24.04 has 0.4.17). It has dropped lua script support since version 0.5 (24.10 has v0.5.6).<\/b><\/p>\n<h4>Step 1: Get the Name of target sound input\/ouput<\/h4>\n<p>Because the sound devices&#8217; ID numbers are dynamic and change often, you need to find out the <code>device.name<\/code> or <code>node.name<\/code> to let WireBlumder know which device you want to configure.<\/p>\n<p>First, run command below to find out the ID of target device\/sink you want to configure:<\/p>\n<pre>wpctl status<\/pre>\n<p>Then, use the command below to display more information about the target object (replace number 49 according to last command).<\/p>\n<pre>wpctl inspect 49<\/pre>\n<p>In the output, copy the value of either &#8220;device.name&#8221; or &#8220;node.name&#8221; for use in next step.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47313\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo-700x486.webp\" alt=\"\" width=\"610\" height=\"424\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo-700x486.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo-300x208.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo-768x533.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wpctl-getinfo.webp 904w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h4>Step 2: Create &amp; Edit lua script file<\/h4>\n<p>Ubuntu 24.04 so far uses lua scripts for WirePlumber configuration. The default config files are located in <code>\/usr\/share\/wireplumber<\/code> directory. While, user can create custom config files under <code>\/etc\/wireplumber<\/code> or <code>~\/.config\/wireplumber<\/code> directories.<\/p>\n<p>1. For current user only, press <b>Ctrl+Alt+T<\/b> on keyboard to open terminal and run commands:<\/p>\n<ul>\n<li>First, create the local wireplumber configuration folder:\n<pre>mkdir -p ~\/.config\/wireplumber\/<\/pre>\n<\/li>\n<li>Then, create the <code>main.lua.d<\/code> sub-folder for storing lua scripts:\n<pre>mkdir -p ~\/.config\/wireplumber\/main.lua.d<\/pre>\n<\/li>\n<li>Finally, create &amp; open a custom script file with name <code>51-alsa-custom.lua<\/code>:\n<pre>gnome-text-editor ~\/.config\/wireplumber\/main.lua.d\/51-alsa-custom.lua<\/pre>\n<p>Here replace <code>gnome-text-editor<\/code> depends on your desktop environment. Use <code>musepad<\/code> for XFCE, <code>pluma<\/code> for MATE, or <code>nano<\/code> command line text editor that works in most desktops.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/create-wireblumber-lua.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47311\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/create-wireblumber-lua-700x287.webp\" alt=\"\" width=\"610\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/create-wireblumber-lua-700x287.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/create-wireblumber-lua-300x123.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/create-wireblumber-lua.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>2. When file opens, paste the content below <strong>and edit accordingly<\/strong>.<\/p>\n<pre>rule = {\r\n  matches = {\r\n    {\r\n      { \"node.name\", \"matches\", \"alsa_output.pci-0000_00_1f.3.analog-stereo\" },\r\n    },\r\n  },\r\n  apply_properties = {\r\n      [\"node.description\"]       = \"Laptop Built-in Speaker\",\r\n      [\"audio.format\"]           = \"S32LE\",\r\n      [\"audio.rate\"]             = 48000\r\n  },\r\n}\r\ntable.insert(alsa_monitor.rules,rule)<\/pre>\n<p><b>IMPARTANT: Mis-configuration and typo errors in this file MAY break the sound output or input! Do it carefully!<\/b><\/p>\n<p>Here you need to:<\/p>\n<ul>\n<li>Replace <code>alsa_output.pci-0000_00_1f.3.analog-stereo<\/code> with yours audio device\/sink node name (See Step 1).<\/li>\n<li>Add more (or delete if need) and change audio settings under &#8220;apply_properties&#8221; section accordingly. Other properties include:\n<ul>\n<li>[&#8220;node.disabled&#8221;] = false,<\/li>\n<li>[&#8220;priority.driver&#8221;] = 100,<\/li>\n<li>[&#8220;priority.session&#8221;] = 100,<\/li>\n<li>[&#8220;node.pause-on-idle&#8221;] = false,<\/li>\n<li>[&#8220;dither.noise&#8221;] = 0,<\/li>\n<li>[&#8220;dither.method&#8221;] = &#8220;none&#8221;, &#8212; &#8220;rectangular&#8221;, &#8220;triangular&#8221; or &#8220;shaped5&#8221;<\/li>\n<li>[&#8220;audio.channels&#8221;] = 2,<\/li>\n<li>[&#8220;session.suspend-timeout-seconds&#8221;] = 5, &#8212; 0 disables suspend<\/li>\n<\/ul>\n<p>For more options, either read the <code>\/usr\/share\/wireplumber\/main.lua.d\/50-alsa-config.lua<\/code> file, or see the <a href=\"https:\/\/pipewire.pages.freedesktop.org\/wireplumber\/daemon\/configuration\/alsa.html\" target=\"_blank\" rel=\"noopener\">official documentation<\/a> for device\/node properties (some may be not available since WireBlumder is old in Ubuntu).<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47312\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua-700x430.webp\" alt=\"\" width=\"610\" height=\"375\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua-700x430.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua-300x184.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua-768x472.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/wireblumber-custom-lua.webp 780w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>For nano command line text editor, press Ctrl+S to save file and Ctrl+X to exit.<\/p>\n<h4>Step 3: Apply Changes<\/h4>\n<p>To apply the new configuration file, simply run the command below to restart the wireblumder service:<\/p>\n<pre>systemctl --user restart wireplumber.service<\/pre>\n<h4>Undo:<\/h4>\n<p>Any incorrect settings or typo errors you made in last step may break the sound output\/input. In the case, just\u00a0<strong>delete that file<\/strong> via the command below:<\/p>\n<pre>rm ~\/.config\/wireplumber\/main.lua.d\/51-alsa-custom.lua<\/pre>\n<p>Then restart the service (see Step 3) should restore everything to default.<\/p>","protected":false},"excerpt":{"rendered":"<p>As you know, Ubuntu uses PipeWire as replacement of PulseAudio for its default sound server since Ubuntu 23.04. And, it now uses WirePlumber to manage pipewire session and policy. With WirePlumber, you may configure more about your sound output and input. You can use Linux command to switch default audio input\/output device, change volume level, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":38513,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[277,2031],"class_list":["post-47308","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-audio","tag-pipewire"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47308"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47308\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/38513"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}