Python Forum
[PyQt] QSoundEffect(pulseaudio): Error decoding source file:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QSoundEffect(pulseaudio): Error decoding source file:
#1
I am using Linux now and I was moving an old project onto my computer from a backup. The project was originally made on Windows. One of the features of the project was to play music, but no matter what I do I can't get it to load the file on my Linux PC.

self.m = QSound("sound.wav") #worked fine on Windows. On Linux I get: QSoundEffect(pulseaudio): Error decoding source file:sound.wav

I have tried:
QSound("./sound.wav")
setting the full path,
creating/using a resource file,
and using a .ogg file. All attempts give the same error. How do I get Qt to play sounds on Linux? (I am using Fedora)

P.S I can load image files just fine, but can't get sound files to work.
Reply
#2
This works for me. To play a ogg file you will need to use QMediaPlayer

#! /usr/bin/env python3.9
from PyQt5.QtMultimedia import QSound
from PyQt5.QtWidgets import QApplication
import sys

app = QApplication(sys.argv)
QSound.play('laser.wav')
sys.exit(app.exec())
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
It likely has to do with which codecs are installed. From the docs:

https://doc.qt.io/qt-5/multimediaoverview.html

Quote:The Qt Multimedia APIs build upon the multimedia framework of the underlying platform. This can mean that support for various codecs or containers can vary between machines, depending on what the end user has installed.
Reply
#4
You want QSound or QSoundEffect?

Example playing loop using QSoundEffect

from PyQt5.QtMultimedia import QSoundEffect
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
import sys
 
app = QApplication(sys.argv)
effect = QSoundEffect()
sound_file = 'test.wav'
effect.setSource(QUrl.fromLocalFile(sound_file))
effect.setLoopCount(QSoundEffect.Infinite)
effect.setVolume(0.25);
effect.play()
sys.exit(app.exec())
Reply
#5
Thanks for the replies. As it would turn out, this is what ended up working for me:

CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(CURRENT_DIR, "sound.ogg")
url = QtCore.QUrl.fromLocalFile(filename)
player = QtMultimedia.QMediaPlayer()
player.setMedia(QtMultimedia.QMediaContent(url))
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020