I found this solution online:
Code: Select all
import pygame
pygame.mixer.init()
sound = pygame.mixer.Sound("/usr/share/scratch/Media/Sounds/Animal/Meow.wav")
sound.play()After messing around I found that if I run one of the Python Games that comes with Raspbian and select "Force HDMI", then my program plays sound correctly. When I exit the game, my program no longer works.
How do I set the audio option from Python? Or is there some other reason why my program is only working while I have another pygame game running? I'm assuming it's due to the audio option.