Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
How can I change playback speed of an audio file in python whilst it is playing?

I've done alot of searching to try and find a way to achieve this but the solutions I've found either don't do what I need or I don't understand them.

I'm looking for a way of playing a sound in python (non-blocking) that allows me to change the playback speed in real time, as it's playing, with no gaps or cutouts.

Changing the pitch is fine. Audio quality isn't even that important.

Most of the solutions I've found only allow setting the playback speed once, before the file is played.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I have done this in my python project. I use VLC to present audio/video within a PyQt5 GUI. The GUI has controls to slow or speed the A/V while it is playing. https://github.com/ccbogel/QualCoder The main python file for displaying audio/video is in: view_av.py and in there is the Class DialogViewAV It imports some additional modules for the GUI and vlc integration, if it helps you get your head around it and extract the bits of code you need.

I have a video explaining using the A/V part of the software and at 45 seconds in I mention the playback speed changing option. https://www.youtube.com/watch?v=TjOfPvvXh7U&t=0s

If I get time, maybe, I can prepare a script to do what you are after.

A/V controls

over 4 years ago · Santiago Trujillo Report

0

I've found a solution, using python-mpv, a wrapper for mpv.io

from pynput.keyboard import Key, Listener
import mpv
speed=1

#quick function to change speed via keyboard. 
def on_press(key):

    global speed

    if key.char == 'f' :
        speed=speed-0.1
        player.speed=speed
    if key.char == 'g' :
        speed=speed+0.1
        player.speed=speed

player = mpv.MPV(ytdl=True)
player.play('/Users/regvardy/mediapipe_faceswap-main/test.wav')
with Listener(
        on_press=on_press) as listener:
    listener.join()
while True:
    
    player.speed=speed

I haven't tested it for stability yet.

It feels like a workaround rather than me actually finding out how to do it so I may try and find a different solution.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!