Posts: 3
Joined: Mon Aug 12, 2019 2:16 pm

Python music player

Thu Aug 15, 2019 8:55 am

Hello there,
I have got a problem with playing sounds on a raspberry pi (Model B with 26 GPIO pins) via pygame in Python. I used the following code (also tried it with a wav but with the same result):

Code: Select all

import pygame

s=pygame.mixer.Sound("/home/pi/Sound1.mp3") #
But I got the following error message:
Traceback (most recent call last):
File "/home/pi/", line 10, in <module>
pygame.error: Unable to open file '/home/pi/Sound1.mp3'

At the second try I used following code:

Code: Select all

import pygame
    #also tried pygame.time.Clock().tick(10) with the same result.
Using a mp3 file it output a loud interferencing noise (sounds like its played 20 times faster) and returned the error message: ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred

Thanks for your help
P.S.: I hope my english is not too bad

User avatar
Posts: 28
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: Python music player

Thu Aug 15, 2019 11:51 pm

try this example with your sound file

Code: Select all

>>> import pygame
>>> pygame.mixer.init(48000, -16, 1, 1024)
>>> sound_1= pygame.mixer.Sound('/home/pi/mysounds/circus.wav')
>>> soundChannel_1= pygame.mixer.Channel(1)

I would rather live in a world where my life is surrounded by mystery than a world so small that my mind could comprehend it.

--- Harry Emerson Fosdick

Return to “Python”