Can I include music in my python game inside the code?

188 Views Asked by At

I want to use the winsound module in my text-based python game to play some background music, however I don't want the user to have to put the music files in the same folder as the game just to play it. Is there any way I can include the music in the file, so if I converrt it to an .exe file it will be included?

Some places online say winsound can use the audio data as a string for the winsound.PlaySound function, but how do you convert a .wav file to a string?

1

There are 1 best solutions below

1
On
import winsound

winsound.PlaySound('song.wav', winsound.SND_FILENAME)
time.sleep(1)

Replace song.wav to any local .wav file you want to use.