Is there any way to run an audio file with PyQt?
Is it possible to do this only with PyQt or do you need to install another library?
Is there any way to run an audio file with PyQt?
Is it possible to do this only with PyQt or do you need to install another library?
If you want to use the native method of PyQt, you have QSound
:
meusom = QSound("alerta.wav")
meusom.play()
There is a method that returns a bool value, so you know if the feature is available:
bool QSound::isAvailable()
This is useful for you to check if you need an alternative notification medium if the platform is unable to play the audio.
The question speaks in PyQt 4, but for those who are using 5, it pays a glance at QSoundEffect
also, more versatile and low latency:
Apparently, QMedia
is only available in PyQt5 (since% requires% requires Qt5), but Python itself can do some things without needing PyQt.
There is the playsound lib, which has no dependencies, to install via QMedia
:
$ pip install playsound
And call it like this:
from playsound import playsound
playsound('/home/pasta/play.mp3')