Play Song In Python Using PlaySound Module
Tags: python, tutorial, programming, codenewbie
Published: 2022-01-29 13:50:31

Hello everyone!! Today we will discuss on how to play song or music using playsound module in  python. 

### <u>Prerequisites</u>:-
1. Download the latest version of **Python** from the official website [python.org](https://www.python.org/) by just clicking on the download option and install  it in your computer as you install other applications.
2. Code Editor like [Visual Studio Code](https://code.visualstudio.com/download) or others of your choice where you can compile and run your python code.
3. If you're using Visual Studio Code, then install this [extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) below.
![Python Extension](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqixkfv9vo4cdj853jan.png) 

---
### <u>Steps to Be Followed</u>:-

1. You have to install the [playsound module](https://pypi.org/project/playsound/) in our computer by running the command `pip install playsound`. 
You can use Command Prompt(CMD) or Windows Powershell as per your choice and just type or copy the command.
If you're using Visual Studio Code then you can run it here in the terminal itself and then press enter. It gets install very soon. 

2. Create a file here in your current folder with ".py" extension.

3. Now type or copy the following two lines of code and paste it in your IDE. You can do the same thing from the [playsound module documentation](https://pypi.org/project/playsound/) and just remove the items from the playsound module and give the correct path of the song or music you wanna play or you can type a  
name of a “.wav” file or “.mp3” file if you have it in the same(current) folder. 

**<u>Note</u>**:- You have to do the same like removing the items from the playsound module give your own path if you're coping the code below.

---
### Code to Run:- 
```
from playsound import playsound

print("Playing Song using playsound")
playsound("C:\\Users\\user\\Music\\Chal Ghar Chalen - Malang 128 Kbps.mp3")

```
---
### ⚠️ <u>Warning</u>
One most important thing here is that you must put double slash as there's only a single slash here because in 99% 
cases it gives an error but in 1% cases it runs without error like this. So, it's always better to use double slashes when you’re giving path of a file.

Now save your file and run it in the terminal and you'll hear the sound. I have used here a Bollywood song **_"Chal Ghar Chalen by Arijit Singh and Mithoon"_** from the movie **_Malaang_**.  

---
### TIPS 
You can also search in the search box of your computer “mp3” and if you have such files and just right-click on it and then click on copy full path option and paste it in the playsound function.  

So, This was just the code of two  lines; very simple and easy.

---
### VIDEO
{% youtube https://youtu.be/jsvV4XrDeDU %}

## Hope this helps you. Thank you for reading, and let's connect!
Thank you for reading my blog. Feel free to subscribe to my [YouTube Channel](https://www.youtube.com/channel/UCsuzc8lqAbgUYo4yzpjtfSw) and connect on [LinkedIn](https://www.linkedin.com/in/susmita-dey-15a15a210/) or [Twitter](https://twitter.com/its_SusmitaDey).
Also, feel free to [support](https://www.buymeacoffee.com/susmitadey) my work.😊