本文介绍了如何使用Pydub更改音频播放速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是音频编辑库的新手- Pydub .我想使用Pydub(例如.wav/mp3格式的文件)更改某些音频文件的播放速度,但是我不知道如何制作.我看到的唯一可能解决此问题的模块是 speedup effect.py 中的模块.但是,没有关于我应该如何称呼它的解释.

I am new learner of audio editing libs - Pydub. I want to change some audio files' playback speed using Pydub(say .wav/mp3 format files), but I don't know how to make it. The only module I saw that could possibly deal with this problem is speedup module in effect.py. However, there is no explanation about how I am supposed to call it.

有人可以解释一下如何在Pydub中执行此任务吗?非常感谢!

Could anyone kindly explain how to do this task in Pydub? Many thanks!

(一个相关问题: Pydub-如何更改帧速率而不更改播放速度,但是我要做的是更改播放速度而不更改音频质量.)

(A related question: Pydub - How to change frame rate without changing playback speed, but what I want to do is to change the playback speed without changing the audio quality.)

推荐答案

sound.set_frame_rate()进行转换,不应引起任何花栗鼠效应",但是您可以做的是更改帧速率(不进行转换) ),然后将音频从那里转换回正常的帧速率(例如44.1 kHz,"CD质量")

sound.set_frame_rate() does a conversion, it should not cause any "chipmunk effect", but what you can do is change the frame rate (without a conversion) and then convert the audio from there back to a normal frame rate (like 44.1 kHz, "CD quality")

from pydub import AudioSegment
sound = AudioSegment.from_file(…)

def speed_change(sound, speed=1.0):
    # Manually override the frame_rate. This tells the computer how many
    # samples to play per second
    sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={
         "frame_rate": int(sound.frame_rate * speed)
      })
     # convert the sound with altered frame rate to a standard frame rate
     # so that regular playback programs will work right. They often only
     # know how to play audio at standard frame rate (like 44.1k)
    return sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate)


slow_sound = speed_change(sound, 0.75)
fast_sound = speed_change(sound, 2.0)

这篇关于如何使用Pydub更改音频播放速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 15:12