2

It works if I try to play a sound/mp3 with mpg321 as a pi user:

mpg321 Yeah-sound.mp3

but

sudo -u pi mpg321 Yeah-sound.mp3

does nothing and

sudo mpg321 Yeah-sound.mp3

leads to error

Can't find a suitable libao driver. (Is device in use?)

I need to allow root user to play a sound or somewhat switch the user to play it. But interestingly this also does not work:

pi@raspberrypi:~/Music $ sudo su pi
pi@raspberrypi:~/Music $ mpg321 Yeah-sound.mp3 

it leads to output similar to a case where the sound is played but nothing really happened. It looks like the sound output is transmitted somewhere else. Any ideas?

I am using latest and pure install of Voice HAT for Raspberry Pi downloaded from github

  • If you suspect that sound output is transmitted somewhere else, try defaulting it to the Audio Jack using amixer cset numid=3 1 or to the HDMI using amixer cset numid=3 2 Make sure to sudo -i before doing that, and when you're done, exit :) – user96931 May 3 at 18:05
  • @user96931 When I did that as user Pi (after sudo su -l pi) nothing change and there is no sound. If I did that as user Root, there is an error "amixer: Cannot find the given element from control default" – United121 May 4 at 9:29
2

All that leads to behaviour specific error related to OS version (Voice HAT on Raspberry Pi). Problem with sudo not playing music was resolved after installing pure "Raspbian Stretch Lite" and adding all necessary drivers.

0

It is unclear why you think you need sudo or what the commands you are trying to run actually do, BUT the issue is almost certainly related to your PATH.

Invoking su does not preserve the environment (see man su) so you loose access to some files accessible to pi.

The way you installed the programs can also affect access.

You can preserve your environment or use full paths on commands.

sudo su -l pi … will "Provide an environment similar to what the user would expect had the user logged in directly".

  • Unfortunately sudo su -l pi does not help. The problem remain the same. The output from the console looks like everything is fine but there is no sound. I checked the PATH and is the same after fresh log-in or after sudo su -l pi – United121 May 4 at 9:35

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.