How do play audio (playsound) in background of Python script?

ScoutEU picture ScoutEU · Jun 10, 2017 · Viewed 26.5k times · Source

I am just writing a small python game for fun and I have a function that does the beginning narrative.

I am trying to get the audio to play in the background but unfortunately the mp3 file plays first before the function continues.

How do I get it to run in the background?

import playsound

def displayIntro():
playsound.playsound('storm.mp3',True)
print('')
print('')
print_slow('The year is 1845, you have just arrived home...')

Also, is there any way of controlling the volume of the play sound module?

I should add that I am using a Mac, and I am not wedded to using playsound, it just seems to be the only module that I can get working.

Answer

Just change True to False (I use python 3.7.1)

import playsound
playsound.playsound('storm.mp3', False)
print ('...')