0

I want to play a sound using playsound module or any other type of sound playing package but there is no sound being emitted and the program is perfectly correct there is no error. I tried everything but there seems to be no result
the code is as follows

import playsound from playsound
playsound('abcd.mp3')

 

here is a screenshot:https://i.stack.imgur.com/y2o2O.jpg

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
rovvan
  • 49
  • 5

4 Answers4

1

Might be your way of writing a syntax is wrong Try this:

from playsound import playsound
playsound('abcd.mp3')
Sheri
  • 1,383
  • 3
  • 10
  • 26
  • yeah it is like that if you can see the screenshot ,im new to stackoverflow and couldent get all of it to be in code ':( – rovvan Apr 04 '20 at 10:13
  • @rovvan if you run the code that you have show us in screenshot you will get `IndentationError` – Sheri Apr 04 '20 at 10:16
  • @rovvan just run the above code that i have provide and then see – Sheri Apr 04 '20 at 10:21
  • `import playsound from playsound` this is not the valid way to import – Sheri Apr 04 '20 at 10:22
  • i changed it and still nothing – rovvan Apr 04 '20 at 10:24
  • @rovvan it's strange. You should properly check your audio device by playing an audio manually – Sheri Apr 04 '20 at 10:31
  • 1
    yes it is , i think it has something to do with the audio file not being found or something like that – rovvan Apr 04 '20 at 10:33
  • @rovvan if your program cannot find the file that you specified it will through and error `Cannot find the specified file. Make sure the path and filename are correct.` like that but in your case it doesn't through an error – Sheri Apr 04 '20 at 10:38
  • its weird really – rovvan Apr 04 '20 at 10:48
1

You have place the audio file abcd.mp3 in the folder(sop\venv\ ) where your game.py file stored and then you run this command to get the audio

from playsound import playsound
playsound('abcd.mp3')

Hope it helps.

Hell Boy
  • 971
  • 2
  • 12
  • 28
  • yes i think it is something to do with the audio file because the file abcd.mp3 dosent appear when writen , and although i did as you suggested there is still no sound – rovvan Apr 04 '20 at 10:25
1

Your code is written in a little bit strange way, try like that:

from playsound import playsound

playsound("abcd.mp3")

hence invert the from and the import and remove the indentation of the second line of code.

In my case it works.

0

As already mentioned in the comments:

Your syntax is correct otherwise you'll get an error. Your mp3 can be found otherwise you'll get an error. Your mp3 plays with sound in another app.

Try this to see if it produces a sound:

import winsound
frequency = 2500  # Set Frequency To 2500 Hertz
duration = 1000  # Set Duration To 1000 ms == 1 second
winsound.Beep(frequency, duration)
Mace
  • 1,355
  • 8
  • 13