The RaspberryPi can be equipped with a speaker in various ways. The easiest way is to connect it via the 3.5mm jack plug. It is also possible to output the sound via the HDMI connection.
Finally, 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 speakers, as described in the articles RaspberryPi - Use RaspberryPi with "Raspotify" as a Spotify speaker or RaspberryPi - Install "Shairport" Airplay on the RaspberryPi is described. .
The following article describes how you can set the standard loudspeaker - which is normally used for sound output.
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Before you start with this article you should have prepared the RaspberryPi so that it is accessible via the network and controllable 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
In the following list you will find all the parts you need to implement this article.
Log in to the RaspberryPi via SSH
To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.
List available speakers
So that you can set the default speaker, you should first check which audio outputs are available. You can also easily find out the ID of the corresponding audio output.
Simply enter the following command in the console of your RaspberryPi.
You will then be shown the available audio outputs and their ID (the number in front). You will need this ID later to set the corresponding output.
Setting the standard speaker
The default loudspeaker - 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 open file, use the arrow keys to navigate further down in the file...
Until you reach the following point.
There you change the part
to set a different audio output as the standard output.
Instead of a "1", you can of course also set a different ID here. It is only important that the ID can be assigned to an audio output (from the previously retrieved list).
Save the changes by pressing CTRL+X, Y and Enter.
To load the changed settings, you should restart the RaspberryPi. Simply enter the following command.
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS 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 think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂