0

I wrote code to play an audio file using python, like below.

def playSound(self):
    os.system('start C:\\Users\\unavaras\\Music\\223.wav')
    time.sleep(10)

It's playing the audio file recursively and it's not being closed untill i manually close it.

Tried below code as well to stop audio, but didn't work

def playSound(self):
    p1 = Popen('start C:\\Users\\unavaras\\Music\\223.wav', shell=True)
    time.sleep(5)
    p1.kill()

In both cases audio is being played recursively.

Can some help me how I can stop the audio after some time or once it finishes playing.

usha n
  • 1
  • 1

1 Answers1

0

I am using linux but you can try this

def playSound(self):
     os.system('timeout 10 start C:\\Users\\unavaras\\Music\\223.wav')

For finding the time duration of audio this link Get .wav file length or duration

  • I tried giving timeout as 10 manually as you mentioned, still the audio file is getting played recursively even after 10 sec untill I close it. – usha n Nov 17 '17 at 11:49