1

This python script is part of a project but that doesn't have relevance. The script is attempting to use the pygame mixer module to load a wav file and play it; this works fine if I input the same code line-by-line in shell but not if I put it into a script and attempt to run it.

from pygame import mixer

mixer.init()
mixer.music.load('sound.wav')
mixer.music.play()

If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.

3
  • Not working how? Commented Oct 13, 2017 at 20:56
  • If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play. Commented Oct 13, 2017 at 20:57
  • @JoshStafford please edit your question to provide additional information - comments can get lost. Commented Oct 13, 2017 at 20:58

1 Answer 1

1

It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.