How to run audio with Pyqt?

Asked

Viewed 298 times

6

Is there any way to run an audio file with Pyqt?

You can do this only with Pyqt or you need to install another library?

2 answers

6


If you want to use Pyqt’s native method, you have QSound:

meusom = QSound("alerta.wav")
meusom.play()

http://doc.qt.io/qt-4.8/qsound.html

There is a method that returns a value bool, for you to know if the feature is available:

bool QSound::isAvailable()

This is useful for you to check if you need an alternative means of notification if the platform is unable to play audio.


The question speaks in Pyqt 4, but for those using the 5, it makes up for a look at QSoundEffect also, more versatile and low latency:

http://doc.qt.io/qt-5/qsoundeffect.html

4

Apparently, QMedia is only available on Pyqt5 (since QMedia requires Qt5), but Python itself can do a few things without Pyqt.

There is the lib playsound, which has no dependencies, can be installed via pip:

$ pip install playsound

And call her that:

from playsound import playsound

playsound('/home/pasta/play.mp3')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.