user3807592
user3807592

Reputation: 55

Minimize delay between two sounds played using winsound.PlaySound

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

1.wav is a sound file of length 01s

There is delay of more then a second between the two winsound.PlaySound calls, even if time.sleep is commented out. But if the parameter for time.sleep is increase for more then 1s then my code runs as it should.

I need to bring the delay down to a 0.15s.

Thanks in advance.

Upvotes: 1

Views: 2023

Answers (1)

James K
James K

Reputation: 3752

The winsound module seems to be unloved. It hasn't adapted to the Python 3 distinction between bytes and strings (http://bugs.python.org/issue11620), so it can't play a .wav file that is stored in memory.

You should probably move to a different audio module such as pyaudio https://people.csail.mit.edu/hubert/pyaudio/

Since the file is a short one. You should read the whole file into memory. If there is still a gap, you can join the file to itself with 0.15 s of silence in the middle and then play (that single file). Audio modules wave, pydub, audioop or audiolab can do the joining. How to join two wav files using python?

Upvotes: 2

Related Questions