本文介绍了如何提高/降低 .wav 文件的播放速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试增加/减少 pydub 中几个 .wav 文件的音高(或速度).我尝试使用 sound.set_frame_rate (我乘以原始帧速率,但没有任何改变).有谁知道如何做到这一点?(最好不要下载额外的外部库).谢谢.

i'm trying to increase/decrease the pitch(or speed) on a few .wav files in pydub.I tried using sound.set_frame_rate (i multiplied the original frame rate, but nothing changed).Does anyone know how this can be done? (preferably without downloading additional external libraries). thanks.

推荐答案

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)

这篇关于如何提高/降低 .wav 文件的播放速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:01