{"id":47388,"date":"2024-10-19T16:09:38","date_gmt":"2024-10-19T16:09:38","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47388"},"modified":"2024-10-19T16:09:38","modified_gmt":"2024-10-19T16:09:38","slug":"ubuntu-airplay-player","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/10\/ubuntu-airplay-player\/","title":{"rendered":"Set Ubuntu PC\/Laptop Speaker as AirPlay Audio Player"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-47389\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apple-airplay-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This tutorial shows how to set up Ubuntu Linux as AirPlay receiver, so your PC speaker can play audio streamed from iPhone, iTunes, iOS devices and third-party AirPlay sources.<\/p>\n<p>For Linux, there&#8217;s a popular free open-source app called <a href=\"https:\/\/github.com\/mikebrady\/shairport-sync\" target=\"_blank\" rel=\"noopener\">Shairport Sync<\/a>. It&#8217;s a AirPlay and AirPlay 2 audio player forked from the original Shairport (discontinued).<\/p>\n<p>Shairport Sync offers full audio synchronisation. It means that audio is played on the output device at exactly the time specified by the audio source.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/iphone-airplay.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-47390\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/iphone-airplay.webp\" alt=\"\" width=\"305\" height=\"660\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/iphone-airplay.webp 305w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/iphone-airplay-139x300.webp 139w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p><b>NOTE 1: Shairport Sync does not support AirPlay video or photo streaming.<\/b><\/p>\n<p><b>NOTE 2: This tutorial is only tested in Ubuntu 24.04. Though, it should work in all current Ubuntu releases.<\/b><\/p>\n<h3>Step 1: Find out Your Audio\/Speaker Device Name<\/h3>\n<p>Before getting started, you need to find out the device name of the sound card and speaker in your Linux computer.<\/p>\n<p>1. First, press <code>Ctrl+Alt+T<\/code> to open up a terminal window. When it opens, run command:<\/p>\n<pre>aplay -l<\/pre>\n<p>If the command not found, run <code>sudo apt install alsa-utils<\/code> to install. And, the command will list all the sound cards and digital audio devices.<\/p>\n<p>In my case (see the screenshot below), my laptop has only one sound card <b>HDA Intel PCH<\/b>, but with 2 speakers, including built-in speaker <b>ALC257 Analog<\/b> and external monitor&#8217;s speaker through HDMI cable named <b>F24G3<\/b>.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47391\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices-700x421.webp\" alt=\"\" width=\"610\" height=\"367\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices-700x421.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices-300x180.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices-768x462.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/aplay-listdevices.webp 818w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>2. Next, run command to list all <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pulse-code_modulation\" target=\"_blank\" rel=\"noopener\">PCMs<\/a>, and find out the output device names, according to the speaker names you got in last step.<\/p>\n<pre>aplay -L<\/pre>\n<p>As the output is a bit too long, you may run the command below instead to filter with speaker name:<\/p>\n<pre>aplay -L |grep F24G3 -B 1 -A 1<\/pre>\n<p>Here:<\/p>\n<ul>\n<li><code>grep F24G3<\/code> &#8211; tell to print lines match the key <b>F24G3<\/b>. Replace it to yours according to the first command output.<\/li>\n<li><code>-B 1<\/code> &#8211; print 1 line of leading context before matching lines.<\/li>\n<li><code>-A 1<\/code> &#8211; print 1 line of trailing context after matching lines.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47392\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names-700x484.webp\" alt=\"\" width=\"610\" height=\"422\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names-700x484.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names-300x208.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names-768x531.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/audio-output-names.webp 987w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>As the screenshot above shows, I can use <b>hw:CARD=PCH,DEV=3<\/b>\u00a0for direct access to the F24G3 HDMI speaker, or <b>hw:CARD=PCH,DEV=0<\/b> (or <b>hw:0<\/b> in short) for direct hardware access to the built-in speaker.<\/p>\n<p>All others (with underlines in screenshots) also work in my tests, but for either software conversions or sample mixing, or other purpose.<\/p>\n<h3>Step 2: Install and configure Shairport Sync<\/h3>\n<p>The software package is available in system repositories of all current Ubuntu releases, including Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04, and Ubuntu 24.10.<\/p>\n<p>To install it, simply open terminal (Ctrl+Alt+T) and run command:<\/p>\n<pre>sudo apt install shairport-sync<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apt-shairport-sync.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47393\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apt-shairport-sync-700x420.webp\" alt=\"\" width=\"610\" height=\"366\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apt-shairport-sync-700x420.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apt-shairport-sync-300x180.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/apt-shairport-sync.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Then, edit its configuration file by running command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/shairport-sync.conf<\/pre>\n<p>Replace <code>gnome-text-editor<\/code> with <code>gedit<\/code> for 22.04 and earlier, <code>mousepad<\/code> for XUbuntu XFCE, or <code>nano<\/code> that works in most desktops.<\/p>\n<p>When file opens, scroll down and find out <b>alsa =<\/b> section. Then, do:<\/p>\n<ul>\n<li>Remove <b>\/\/<\/b> at the beginning of the &#8220;output_device&#8221; line to enable it.<\/li>\n<li>Set the &#8220;output_device&#8221; value according to Step 1. In my case, I can use <b>hw:CARD=PCH,DEV=3<\/b> for HDMI speaker or <b>hw:CARD=PCH,DEV=0<\/b> for built-in speaker.<\/li>\n<li>(Optional) For choice, you may enable and configure more rules, such as <code>mixer_device<\/code>, <code>output_rate<\/code>.<\/li>\n<\/ul>\n<p>When editing done, save file. For nano, press Ctrl+S to save and Ctrl+X to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47394\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config-700x416.webp\" alt=\"\" width=\"610\" height=\"363\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config-700x416.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config-300x178.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config-768x456.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/shairport-sync-config.webp 980w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 3: Enable and restart Shairport Sync service to apply<\/h3>\n<p>The software requires the avahi-daemon to be running. First, run command to make sure the service is in active running state.<\/p>\n<pre>systemctl status avahi-daemon.service<\/pre>\n<p>In case it&#8217;s not running, run <code>systemctl start avahi-daemon.service<\/code> to start it.<\/p>\n<p>And, restart the Shairport Sync service to apply change:<\/p>\n<pre>sudo systemctl restart shairport-sync.service<\/pre>\n<p>For Debian and other Linux, the service may NOT be enabled by default after installed the software package. In the case, run <code>sudo systemctl enable --now shairport-sync.service<\/code> to enable and start it.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/restart-shairport-sync.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47395\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/restart-shairport-sync-700x516.webp\" alt=\"\" width=\"610\" height=\"450\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/restart-shairport-sync-700x516.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/restart-shairport-sync-300x221.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/restart-shairport-sync.webp 714w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Finally, in your iOS device play some music and select casting to your speaker through AirPlay.<\/p>\n<p>NOTE: there will be about <b>2 or 2.5 seconds latency<\/b> specified AirPlay source. <b>And, in my case the sound is very low. Try pressing volume buttons in iOS device to turn sound up\/down in case you hear nothing.<\/b><\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to set up Ubuntu Linux as AirPlay receiver, so your PC speaker can play audio streamed from iPhone, iTunes, iOS devices and third-party AirPlay sources. For Linux, there&#8217;s a popular free open-source app called Shairport Sync. It&#8217;s a AirPlay and AirPlay 2 audio player forked from the original Shairport (discontinued). Shairport [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":47389,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2225],"class_list":["post-47388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-airplay"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47388","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=47388"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47388\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/47389"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}