1

I'm trying to test the audio through the headphone jack using aplay /usr/share/sounds/alsa/* on Rasbian 5.10.17 on a Raspberry Pi 3 B+. This works fine on the pi user, but not on root or another user I've created for my projet. When running the command using 1) sudo, 2) logging in as root using sudo -i, or 3) logged in as the other user, I get the same error:

aplay: set_params:1403: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 16
CHANNELS: 1
RATE: 48000
PERIOD_TIME: 125000
PERIOD_SIZE: 6000
PERIOD_BYTES: 12000
PERIODS: 4
BUFFER_TIME: 500000
BUFFER_SIZE: 24000
BUFFER_BYTES: 48000
TICK_TIME: 0

The weird thing is that it plays the first file /usr/share/sounds/alsa/Front_Center.wav, but the error occurs on the second file. I've tried to add the other user to relevant groups such as audio, pulse, dialout, cdrom, video, plugdev, etc. Basically the same groups as the pi user.

The second issue is that when using espeak for text-to-speech the screen is filled with errors:

other-user@raspberrypi:~ $ espeak "hello"
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5014:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

The same errors occurs for the three cases 1)-3) above.

Using omxplayer works fine in all the three cases 1)-3) above, it is only aplay and espeak there are troubles with. So running espeak with the -w argument works and playing it using omxplayer works, but is not ideal.

What is the problem? How can I fix it?


Some more information:

Running aplay -l I get:

**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7

and aplay -L

default
    Playback/recording through the PulseAudio sound server
null
    Discard all samples (playback) or generate zero samples (capture)
jack
    JACK Audio Connection Kit
pulse
    PulseAudio Sound Server
sysdefault:CARD=Headphones
    bcm2835 Headphones, bcm2835 Headphones
    Default Audio Device
dmix:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct sample mixing device
dsnoop:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct sample snooping device
hw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct hardware device without any conversions
plughw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Hardware device with all software conversions
usbstream:CARD=Headphones
    bcm2835 Headphones
    USB Stream Output
4

When your custom user fails to play the audio, are you also logged to the system as the pi user? audio group is tricky, it allows users in that group to get exclusive access to audio HW, preventing other users from using it:

Adding users to the audio group allows direct access to devices. Keep in mind, that this allows applications to exclusively reserve output devices. This may break software mixing or fast-user-switching on multi-seat systems. Therefore, adding a user to the audio group is not recommended by default; unless you specifically need to.

And from the Ubuntu wiki:

As a practical rule of thumb for Debian and Ubuntu systems, there should be no users in the audio group.

Pi OS is configured in a way to make everything work for the pi user, more or less exclusively, because it will make it easy for 99% of the users. That's why pi is in the audio group. One solution is to use the pi user in your project, as intended.

If you must have a different user for this project, consider removing the pi user from the audio group, or even stopping using it altogether. Than means no auto-login as pi, and no manual logins. You should even be able to remove the pi user completely.

2
  • 1
    Yes, this solve the issue! Thanks! It seems to be what you said that only a single user can be in the audio group. When I removed the pi user from the audio group, my other-user was able to play all the files using aplay. The reason I wanted to create another user for this project is to more easily let others log in without giving them sudo access, but as far as the project goes, it seems better to just use the pi user as Raspberry Pi intends me to and not have to deal with issues like this. – eirik-ff Mar 22 at 16:13
  • 1
    @eirik-ff That's great news! good luck with your project. BTW, if your project needs multiple users, you would hit issues like this one sooner or later, so it's good this was solved early on. – Dmitry Grigoryev Mar 23 at 8:09
2

Caveat: I know nothing about aplay or espeak. However, I can sometimes read & comprehend a man page. Simon's answer may be generally correct in that your "other-user" needs to be added to the group audio, but I don't believe you can add a user to a group with the command he's given: sudo useradd -G audio. To be completely fair, group and user administration on Debian (and therefore RPi OS) is confusing!

_If_ adding "other-user" to the group audio is the solution, try this instead (as user pi):

pi@raspberrypi:~ $ sudo usermod -a -G audio other-user 

Note: that is usermod - not useradd

Afterwards, you can check that this was successful (again, as user pi):

pi@raspberrypi:~ $ groups other-user

You should see the group audio in the output list.

6
  • Unix command names are confusing in general ("cat"? what cat?), but the Windows equivalent (Import-Module Microsoft.PowerShell.LocalAccounts; Add-LocalGroupMember -Group "Audio" -Member "OtherUser") is like a typing training. – Dmitry Grigoryev Mar 22 at 9:17
  • @DmitryGrigoryev: Yes - god save us from that Windows bunkum... but my comment was regarding user & group admin relative to other Linux commands. Maybe it's a mental block, but I struggle more with that class of commands than others. – Seamus Mar 22 at 9:22
  • Yes, I didn't notice that he wrote useradd instead of usermod, but as I stated in the original post, the other-user is already in the audio group from running sudo usermod -a -G audio other-user. However, as I said in the comment under Simon's answer, added other-user to the audio group did not solve the issue. – eirik-ff Mar 22 at 16:01
  • @eirik-ff: Yes - I wasn't quite sure that's what you meant, but I knew that useradd wasn't going to get your other-user added to any group - just trying to help move things forward. Oh, BTW - when you "accept" an answer, it is customary to also "upvote" it. The cost to you is the same :) – Seamus Mar 22 at 16:46
  • 1
    I did not know there was a rep limit to upvote an answer - sorry about that. But you should have enough rep now :) – Seamus Mar 23 at 3:18
-1

You need to add your user into the 'audio' group to allow them access to audio devices and resources.

sudo useradd -G audio <Your username>
4
  • 1
    I've done that, but it doesn't help. To be fair, root is not in that group, but my other user is, so then it should work for that user. – eirik-ff Mar 21 at 22:27
  • 1
    That's not the correct command to add a user to a group. – Seamus Mar 22 at 6:22
  • Forgot to code block the command..Thanks You don't need to give permissions to root user.. it always has permission.. – Simon Banks Mar 22 at 8:12
  • 1
    Adding users to a group is done with gpasswd or usermod. useradd is a command which creates new users. – Dmitry Grigoryev Mar 22 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.