2

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ricky Kresslein
  • 372
  • 1
  • 13
  • Do you mean that the pitch is absolutely higher than expected (for instance, very high even at 1.25)? Otherwise, if at 2x it's playing one octave higher, that's exactly what playback *rate* change is. – musicamante Feb 11 '21 at 15:06
  • Unfortunately I don't know enough about octaves to say exactly, but even at 1.25 the people speaking sound a bit like chipmunks, and by 1.5 it's really bad. In python-vlc I can speed it up to 2x and the voices sound normal, it's just faster. Is there another way to do this in QMediaPlayer if playbackRate is not the way? – Ricky Kresslein Feb 11 '21 at 17:08
  • See: https://stackoverflow.com/q/33088043/984421. – ekhumoro Feb 11 '21 at 20:39
  • Thank you. I've seen that--correct me if I'm wrong, but I don't think that will work for me since I'm playing the media directly from a URL, and my audio is usually in MP3 format and it looks like SoundStretch only supports WAV. – Ricky Kresslein Feb 11 '21 at 22:06
  • 1
    @RickyKresslein I wasn't suggesting it as a solution (I'd have closed this as a dupe if it was). The point is that pitch-correction isn't currently supported by Qt - so you cannot avoid a dependency of some kind. – ekhumoro Feb 12 '21 at 19:36
  • @ekhumoro Okay, gotcha. Thank you. I'll stick with VLC for now then. – Ricky Kresslein Feb 13 '21 at 09:38
  • 1
    @RickyKresslein the point is that sound is based on frequency: if you double the speed, you double the frequency, so you get the sound with a higher pitch (an octave higher). What you can get on VLC (or other cases like Youtube) is a software algorithm that makes an interpolation of the audio signal by "cutting out" samples when speed is higher or by doubling them when lower (actually it's a bit more complex, but that's the base concept). Have you ever listened to a tape or record player playing at different speeds? – musicamante Feb 14 '21 at 00:01

1 Answers1

2

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

Hamza
  • 132
  • 5