Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I play audio (playsound) in the background of a Python script?

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 a way of controlling the volume of the playsound module?

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.

like image 572
ScoutEU Avatar asked Nov 27 '22 23:11

ScoutEU


1 Answers

Just change True to False (I use Python 3.7.1)

import playsound
playsound.playsound('storm.mp3', False)
print ('...')
like image 65
χρηστος απατσιδης Avatar answered Dec 05 '22 04:12

χρηστος απατσιδης