Skip to main content

Raspberry Pi audio playback from Python

Want to play audio on your Raspberry Pi running Raspbian, while logged in to a non-root user account? Me, too!

Seems like such a simple task.

Consider the following code snippet using PyGame:

import time
import pygame
while == True:

Let's try it:

$ python
Traceback (most recent call last):
  File "./", line 3, in <module>
pygame.error: No available audio device

But, if you run the script using sudo, it plays as expected.

The solution? Add non-root users to the `audio` group [1] in order to play audio.

$ sudo usermod -a -G audio <username>

Important: Log out of the user account, then log in again in order to force the new group membership to take effect.



* Debian SoundFAQ