Playing audio

Hello r/learnpython,

I am mostly new to python and I'm using Spyder ide through anacanda on Windows. I want to be able to play mp3 audio files for a project I'm doing, but I'm having quite a bit of difficulty. I did a lot of research online but my limited base knowledge is making it hard for me to understand a lot of the more technical stuff. I tried importing vlc but that doesn't work (is it only for mac?). I also tried winsound but I think it only works for .wav files. I also tried sounddevice but that was too confusing. I also followed some links to some git website but I couldn't figure out how to use anything there.

If there is a better way to play audio could someone please explain it to me. Or if I'm on the right track could someone explain what I'm doing wrong and how to do it better.. Im also confused about if downloading a package through the promp will make it accessable in spyder. My overall coding knowledge is limited to basic c++ and basic Java from ap com sci and only a few days of figuring out python on my own, so I know I don't have a lot to work off of.

TLDR; I need help playing audio

Posted Oct 23, 2018, 3:27 AM UTC

35
Allanon001•
2
reddituser716OP•

Thank you so much, it works perfectly!

1
reddituser716OP•

Now the hard part is getting it to stop playing

1
Allanon001•

Just thought you wanted to play a mp3, try using pygame:

To install: pip install pygame

To play an mp3:

from pygame import mixer
from time import sleep

mixer.init()
mixer.music.load('file.mp3')
mixer.music.play()
sleep(10)
mixer.music.stop()
2
reddituser716OP•

Ok thank you so much

1
[deleted]•

[deleted]

1