Learn Before
Code

Creating/Playing a Sound Object in Pygame

You can create a Sound object by using the Sound() constructor method and passing in the sound filename. Pygame will accept both .wav and .mp3 filetypes, but .wav is the most consistent without any glitching or audio lag.

death_sound = pygame.mixer.Sound("death.wav")

You can then play the sound using the play() method.

pygame.mixer.Sound.play(death_sound)

0

1

Updated 2021-08-02

Tags

Python Programming Language

Data Science