QMediaPlayer does provide a stream of the audio data which is playing

Heads up! You've already completed this tutorial.

johnh100008948 | 2020-12-07 16:42:45 UTC | #1

From Martin Fitzpatrick's https://www.pythonguis.com/tutorials/failamp-multimedia-player/

He states that "QMediaPlayer does provide a stream of the audio data which is playing"

I have been trawling the docs all day, but can not find the stream. I intend to add a decibel meter to Martin's project.

Any ideas?

Thanks for any advice.


martin | 2021-05-07 07:49:29 UTC | #2

Hi @johnh100008948 welcome to the forum.

This is a nice project, I mentioned it on the tutorial as it was something i was planning to do but not yet got around to. Looking at it now, I'm not sure how to go about it either.

  1. the "stream" I mentioned there might in fact be the stream that's available when loading from an audio stream -- I think you can see the current data/access the stream as a file device. But that doesn't really help for showing what is currently playing.
  2. there is an example of an equalizer on the Qt website (this is QML but comparable). This looks promising until you realise they actually pre-calculate the bars loading them in via a separate file.

But all is not lost. There is actually a very nice PyQt5 media player with graphic equalizer called Milkplayer. If you look at the visualizer code what they do there is open the same file in a separate thread using pydub. The QMediaPlayer current positions are used to extract regions of the audio, which is then processed to generate the equalizer.

You could do something similar, and just return the total amplitude instead -- Each AudioSegment in pydub has a . dBFS property which gives you the loudness.

Hope that helps? I'll update the tutorial when I'm back in the office next week.


Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt5
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

QMediaPlayer does provide a stream of the audio data which is playing was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.