sound.set_frame_rate()进行转换,不应产生任何“花栗鼠效应”,但您可以更改帧速率(不进行转换),然后将音频从那里转换回正常的帧速率(如44.1 kHz,“CD质量”)。
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)