【问题标题】:how to increase/decrease playback speed on .wav file?如何增加/减少 .wav 文件的播放速度?
【发布时间】:2017-04-14 09:27:44
【问题描述】:

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

【问题讨论】:

  • 您是否将sound.set_frame_rate() 的结果分配给了一个新的变量?音频片段是不可变的,任何方法都不会导致更改,就地(它们都返回一个新的音频片段)
  • @Jiaaro 谢谢,我现在试过了。它似乎有一些效果,但只有当我让帧速率变慢时(例如 44100/2,44100/6 等),但当我让它变大时,什么也没有发生。你知道为什么吗?你还知道我可以用 pydub 做的任何其他效果吗?

标签: python-2.7 pygame pydub


【解决方案1】:

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)

【讨论】:

  • 谢谢!您能否更深入地解释这些行的作用? sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={ "frame_rate": int(sound.frame_rate * speed) }) return sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate)
  • @Sh0z 我添加了一些解释性 cmets
  • 减速听起来很吓人
猜你喜欢
  • 2014-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多