playsound module in Python

In this tutorial, we will discuss how to use playsound module in Python. By using playsound module we can play sound. This is a cross platform module that can play audio files.

Playsound module contains only one function that is playsound().

This module is available and works on both Python 2 and Python 3, and is tested to play wav and mp3 files only.

Let’s see the command to install playsound package

pip install playsound

To know more about this module visit https://pypi.org/project/playsound/

playsound() contains two arguments:

  • Local file path or a URL.
  • block(default True) can also set to False for running asynchronously.

playsound in Python for mp3 format

#import playsound module
from playsound import playsound

#for playing song.mp3 file
playsound("/path/song.mp3")
print("playing sound")

In the above code, in the place of path you have to write the location of your file.

playsound in Python for wav format

#import playsound module
from playsound import playsound

#for playing song.wav file
playsound("/path/song.wav")
print("playing sound")

In the above code, in the place of path, you have to write the location of your file.

Also read:

Leave a Reply

Your email address will not be published. Required fields are marked *