65

I can't get the audio running. I don't hear anything and can not play anything.

Is there a solution to enable audio?

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Itay Grudev
  • 1,576
  • 3
  • 15
  • 19
  • 7
    Please add more information to make this a more useful question for the future, even if it has already been answered. – ramblinjan Jun 12 '12 at 20:59
  • 1
    Distro tag required. As well as what audio output you are trying to use. – Jivings Jun 12 '12 at 22:54
  • 1
    Guidelines: http://stackoverflow.com/questions/how-to-ask

    Luckily the current best answer is broad enough to cover your question. However, it's better for future users of the site if you give your specific setup to allow for a specific answer.

    – ramblinjan Jun 13 '12 at 18:14
  • My problem was low volume for master output. –  Feb 23 '13 at 19:12

12 Answers12

69

Sound does not work with an HDMI monitor

This is caused by some computer monitors which select DVI mode even if an HDMI cable is connected. This fix may be necessary even if other HDMI devices work perfectly on the same monitor (or TV)! Edit the /boot/config.txt file (see Raspberry-Pi Configuration File) and add the following line to the configuration file:

hdmi_drive=2

Sound does not work at all, or in some applications

Sound is disabled by default because the ALSA sound driver is still "alpha" (not fully tested) on the R-Pi. To try out sound, from the command prompt before "startx", type

 sudo apt-get install alsa-utils
 sudo modprobe snd_bcm2835
 sudo aplay /usr/share/sounds/alsa/Front_Center.wav

By default output will be automatic (hdmi if hdmi supports audio, otherwise analogue). You can force it with:

sudo amixer -c 0 cset numid=3 <n>

where n is one of: 0 = auto, 1 = headphones, 2 = hdmi. (source) If you are running Debian, try

cd /opt/vc/src/hello_pi
 make -C libs/ilclient
 make -C libs/vgfont
cd hello_audio
 make
 ./hello_audio.bin

to test analogue output. And to test HDMI.

./hello_audio.bin 1

Also note that you may have to add your user to the audio group to get permission to access the sound card.

gpasswd -a <username> audio

Making the changes permanent

sudo apt-get install alsa-utils is permanent, but sudo modprobe snd_bcm2835 only initialises the driver for the current session. To ensure the module is initialised on boot, add snd_bcm2835 to /etc/modules (source).

Itay Grudev
  • 1,576
  • 3
  • 15
  • 19
  • 4
    aplay -l is also a useful command for enumerating if any ALSA devices exist. – stsquad Jun 21 '12 at 13:42
  • 2
    This is outdated information as of Jan 2013. alsa-utils is installed by default, and lsmod shows snd_bcm2835 is there without having to do anything. – CaptSaltyJack Jan 03 '13 at 17:38
  • Maybe so, but the problem might still occur on old devices and some distros – Itay Grudev Jan 04 '13 at 00:51
  • 1
    I had snd-bcm2835 in /etc/modules when it should have been snd_bcm2835. Once I changed that, it worked. – daviewales Jun 05 '13 at 04:21
  • 1
    You may also need to change the mixer volume if not running in a desktop environment with a GUI control for it. I don't know whether it was just my pi, or if it's a common issue, but my volume was set to -25dB, which is virtually inaudible. amixer cset numid=1 0 sets it back to a reasonable level. – Jules Apr 11 '16 at 22:09
  • With my Raspberry Pi 3 Model B running Linux raspberrypi 4.9.41-v7+ (uname -a output) all I had to do was to use the command sudo amixer -c 0 cset numid=3 1 in an xterminal window. Started listening to a YouTube video and it was very low level of sound. Checked the volume control from the Speaker icon on the desktop menu bar and the volume setting was low there so changed to 53 and it is working fine. I have a Logitech 2.1 (two desktop satellites and one powered subwoofer) and I plugged the lead of the speakers into the headphone jack. – Richard Chambers Sep 23 '17 at 22:21
  • For me amixer cset numid=3 100% worked on my RPi 4. – Anders Feb 28 '20 at 02:46
11

I think I have a way for solving your problem, try to type omxplayer -o local xxx.mp3(for mp3 file) or omxplayer -o local xxx.mp4(for mp4 file) to hear sound from raspi over your headphone. And you can also type omxplayer --help for more usage about omxplayer.

chinashieh
  • 141
  • 1
  • 2
  • 7
  • This worked for me. Oddly, when playing videos in VLC or Youtube or playing an audio on Audacious, I hear nothing. But omxplayer worked. So I went to audio settings in Audacious and tried the various configurations. Alsa with hwCARD=Headphones -bom2835 Headphones worked. Oddly, I wasn't using headphones. It was a 2.1W USB speaker with a 3.5mm jack. – Nav Oct 09 '20 at 16:23
  • 1
    OMX is special... it ignores everything and talks directly to hardware. – Scalway Jun 18 '21 at 07:59
10

I also ran into the same problem with my Raspberry Pi 2. I connected my Pi to my HD TV via an HDMI cable. My solution:

Set the audio output using the following command:

amixer cset numid=3 2

I tested the sound output using the following command, but no sound was heard:

speaker-test -c2 -t wav

To enable HDMI sound, I followed the directions found here

sudo [your favourite editor] /boot/config.txt

Uncomment line #hdmi_drive=2

Reboot Pi using the following command:

sudo shutdown -r 0
Ghanima
  • 15,855
  • 15
  • 61
  • 119
user29132
  • 101
  • 1
  • 2
  • I didn't need to do the first two steps, and I'm not sure they even need to be in the answer, but the rest worked for me with a Raspberry Pi 2. – James Skemp Aug 27 '15 at 00:05
  • I did "amixer cset numid=3 2" and my audio stopped working. How can bring it back to the previous state? – Bartek Pacia Feb 07 '21 at 14:01
5

I'm running OSMC, which runs Debian, and I got sound to play through my TV speakers, which is connected by HDMI. https://youtu.be/p2ljmTE67gs

If this is what you're trying to do, try adding dtparam=audio=on to /boot/config.txt

Original solution posted here: https://discourse.osmc.tv/t/alsa-doesnt-work-after-last-update/10600

tonyslowdown
  • 151
  • 1
  • 3
  • This answer is going to be particularly appropriate for people upgrading older installs to something more modern. – Sam Hartman Oct 06 '18 at 18:15
5

This is a common bug. I think what's breaking ALSA is PulseAudio. If you want to use ALSA (Default, recommend by Tux) use sudo apt-get remove PulseAudio

For other fixes, try the wiki. It all depends. Try this first (as this is the most common)

Ghanima
  • 15,855
  • 15
  • 61
  • 119
Algo
  • 79
  • 1
  • 3
  • 1
    What bug are you referring to? Do you have a reference? – bzeaman Jul 18 '16 at 13:00
  • 1
    This fixed it for me. I use PuleAudio to play sound to a bluetooth headset. When I tried to use the analog audio port, I could not get it to work, and everything in my config was correct. I removed PulseAudio, and the analog audio port works. Too bad I have to unistall and reinstall a package to switch between bluetooth and the 3.5 mm jack. – MidnightJava Jul 29 '18 at 03:18
  • Thanks for pointing out the problem with pulseaudio! Your suggestion fixed my problem. – Noctis Skytower Aug 04 '20 at 21:20
3

My current working hypothesis is that, for me at least, the audio depends somehow on the desktop environment. I have a Raspberry Pi 2, running Raspbian, installed from NOOBS. I've wiped it clean and reinstalled Raspbian dozens of times. The sound works when I first install Raspbian. The next thing I habitually do is remove the LXDE desktop environment and replace it with XFCE desktop environment, and sometime after that, I notice that the sound has stopped working. Switching desktop environments must be breaking my audio. I don't know whether it's removing LXDE or installing XFCE that breaks it.

Perhaps the person is correct who suggested that the culprit is PulseAudio, and installing XFCE installs PulseAudio. Right now, "lxde" is installed, "xfce4" is not installed, "pulseaudio" is not installed, and the sound is working.

Daniel
  • 31
  • 1
2

I ran into a problem where sound did not work or static played instead of my recording. But it was a problem with my approach, not the Pi itself. I'm using Raspbian 3.6.11 (2013-02-09-wheezy-raspbian).

Primarily, I tried to play an MP3 file with aplay, which only seems to support WAVs. Also, some of the MP3 files I used may not have been created with a compatible codec. To test the sound output on your Pi, I found it best to the sample audio files that come with the Raspbian OS. Also ensure that you use a player appropriate for the audio format. For example:

  • Use aplay for .wav files. For example: aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav (there are lots of sample audio files in /usr/share/scratch/Media/Sounds).
  • Use omxplayer or mpg123 for .mp3 files. For example: use omxplayer /usr/share/scratch/Media/Sounds/Effects/WaterDrop.mp3 or alternatively mpg123 /usr/share/scratch/Media/Sounds/Effects/WaterDrop.mp3 (If you don't already have mpg123, you should be able to install it with the command sudo apt-get install mpg123).
  • Use amixer to control the volume output. For example: amixer cset numid=1 50% sets the headphone jack volume output to fifty percent.

For more information on audio out commands, I found the following web site useful: http://blog.scphillips.com/2013/01/sound-configuration-on-raspberry-pi-with-alsa

For what it's worth, I was also experiencing a popping sound caused by a voltage jump when the audio starts and stops. That issue is now fixed in the Pi firmware.

Steve HHH
  • 153
  • 5
  • AFAIK that bug should have been fixed in one of the audio driver updates ... – Itay Grudev Mar 21 '13 at 20:21
  • 1
    You're right. I was probably just doing it wrong, but others may have the same issue, so I've updated my post with my findings. Thanks Itehnological! – Steve HHH Mar 25 '13 at 18:38
2

I was having problems with the analog audio output myself. Came to this thread among others to try to solve. In the end, it turns out I only needed to right-click on the audio icon in my toolbar and change the selection from HDMI to Analog. This probably doesn't solve your problem, but it might help someone else who isn't hearing audio and who missed that easy solution.

1

On my Raspberry Pi the "speaker-test" worked without any extra hardware added. Then I added some webcams. The default device had changed and I found this question How to make Alsa pick a preferred sound device automatically? from which solution #1 worked for me.

... create /etc/asound.conf with following: ...

Replace "card 1" with the number of your card determined above.

Mark
  • 11
  • 2
1

My solution came from this page:

[https://www.raspberrypi-spy.co.uk/2013/06/raspberry-pi-command-line-audio/][1]

And was this:

sudo modprobe snd_bcm2835
0

I ran into this problem while trying to get Amazon Voice Services working on a Raspberry Pi 3/3+. I made sure that analog audio was selected. Also using aplay worked.

It turns out AVS uses the autoaudiosink element, which in turn was selecting the omxhdmiaudiosink element, which had a higher priority than the alsasink element. In file /etc/xdg/gstomx-rpi.conf there is a section for omxhdmiaudiosink which I simply commented out. After doing so, AVS worked fine (for the most part--the responses were getting cut short by about ~0.25 seconds).

I suppose I could have changed the priority as well.

-1

If you want a simple answer there are 3 options:

  1. hdmi: omxplayer -o hdmi filename.mp4
  2. both: omxplayer -o both filename.mp4
  3. local: omxplayer -o local filename.mp4

If you want it playing though your monitor do

omxplayer -o hdmi

If you want both then do

omxplayer -o both

If you have headphones and you want to plug it in your Raspberry do

omxplayer -o local

and then add your file name and there you go; it's that easy

Phil B.
  • 5,043
  • 15
  • 30
anon
  • 11
  • If you read the accepted answer the problem is that sound is not enabled at the board level so a program specific setting will not work. Second what does omxplayer have to do with the original question? – Steve Robillard Aug 05 '15 at 04:49
  • This worked for me, I was able to play wav file but mp3 werent working with omxplayer command. I put on the -o local flag it worked. Still figuring out why... for I already set my output to headphone and tried all other things – Taran J Apr 19 '16 at 12:08
  • OMX is special. It is compiled only to RPI and ignores everything. It talks directly to hadrware and it makes it weird. – Scalway Jun 18 '21 at 08:05