The RaspberryPi can be equipped with a speaker in various ways. The easiest way is the connection via the 3.5mm jack plug. There is also the option of having the sound output via the HDMI connection.
Ultimately, the sound can also be output via a connected USB speaker.
This is particularly useful if you want to use your RaspberryPi as a Spotify or AirPlay loudspeaker, as described in the articles RaspberryPi – Use RaspberryPi with “Raspotify” as Spotify speaker or RaspberryPi – Install “Shairport” Airplay on the RaspberryPi.
The following article describes how you can set the standard speaker – through which the sound output normally takes place.
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
Affiliate links / advertising links
The links to online stores listed here are so-called affiliate links. If you click on such an affiliate link and store via this link, Nerdiy.de receives a commission from the online store or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Before you start with this article, you should have prepared the RaspberryPi so that it can be reached via the network and controlled via SSH.
The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi - Setup for nerdiys!
RaspberryPi - The first configuration!
RaspberryPi - Control the RaspberryPi via SSH
- none -
Log in via SSH on the RaspberryPi
To get started, you first need to log in to RasPi with SSH on Putty. How to do it is described in the article
List available speakers
So that you can set the standard loudspeaker, you should first check which audio outputs are available. So you can easily find the associated ID of the corresponding audio output.
Simply enter the following command into the console of your RaspberryPi.
The available audio outputs and their ID (the number in front of them) will then be displayed. You will need this ID later to set the corresponding output.
Set the default speakers
The standard audio out – which is normally used for output – can be set via the ALSA configuration file.
To do this, open the configuration file with the following command.
In the opened file you can now navigate further down with the arrow keys in the file …
Until you have arrived at the following point.
There you change the part
to set another audio output as the standard output.
Instead of a "1" you can of course also set another ID here. It is only important that the ID can be assigned to an audio output (from the list previously called up).
Save the changes by pressing CTRL + X, Y and Enter.
To load the changed settings you should restart the RaspberryPi. Just enter the following command.
Have fun with the project
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate that I share this information with you, I would be happy about a small donation to the coffee box. 🙂
Thank you for the article. Unfortunately it doesn't quite work for me. The USB sound card is shown as "2 snd_usb_audio"; So I replace the 0 in the configuration file with a 2. After a restart, this is still 2, but I still get no sound from the sound card. Do you have an idea what it could be?
Thank you very much 🙂
did you enter the “2” for both values (i.e. defaults.ctl.card and defaults.pcm.card)? 🙂