QMediaPlayer setPlaybackRate > 1 causes high-pitched audio

687 views Asked by At

I'm creating an app that plays podcasts in PyQt5. It retrieves the MP3 from a URL and plays it using QMediaPlayer. The issue I'm running into is when I wish to play these podcasts back at a faster speed. Using setPlaybackRate(rate) I change the rate between 1, 1.25, 1.5, 1.75, and 2. Anytime the rate is greater than 1, the voices turn into high pitched chipmunk voices.

Are there any ways around this? I was using python-vlc, which worked fine in this regard, but wanted to switch to QMediaPlayer to remove the VLC dependency. I really appreciate any help.

1

There are 1 answers

1
Hamza On

According to Qt Documentation

Qt Multimedia features for Windows are implemented in two plugins; one using the Microsoft DirectShow API, and another using WMF (Windows Media Foundation) framework. DirectShow API was introduced in Windows 98, and gradually deprecated from Windows XP onwards. Media Foundation framework was introduced in Windows Vista as a replacement for DirectShow and other multimedia APIs. Consequently, WMF plugin in Qt is supported only for Windows Vista and later versions of the operating system.

By default, the Qt prefers the DirectShow instead of windowsmediafoundation. Now let's come to your answer.

The Directshow plugins which was the older plugin changes the pitch when you change the playbackrate

While the newly introduced Windows Media Foundation (WMF) doesn't affect the pitch

So all we have to do is switch from directshow to windowsmediafoundaton

Just add the below code at the top of your Code before importing anything else

import os
os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = "windowsmediafoundation" 

This might do the work, if the audio is not audible after adding this code then all you have to do is download some codecs from here https://codecguide.com/media_foundation_codecs.htm