Python winsound – Loop WAV file

In this post we will be creating a Python script that will play a WAV file in loop whilst running, to do this we will be using the Winsound module which provides access to the basic sound-playing machinery provided by Windows platforms. Note that this module will not work with MAC and Linux operating systems.

See the snippet of code below which will play the WAV file named ‘file.wav’. We use the ‘SND_ASYNC’ function which will allow the WAV file to play asynchronously and to avoid blocking, we also utilize the ‘SND_LOOP’ function which will play the file repeatedly.

import winsound


print("Now playing file in loop. 🎶")

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply