增加/减少WAV文件Python的播放速度 [英] Increase/Decrease Play Speed of a WAV file Python

查看:347
本文介绍了增加/减少WAV文件Python的播放速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python wave模块更改某个WAV音频文件的播放速度(增加或减少).

I want to change play speed (increase or decrease) of a certain WAV audio file using python wave module.

我尝试了以下事情:

  1. 读取输入文件的帧频.
  2. 将帧频提高一倍.
  3. 使用output_wave.setparams()函数编写一个具有提高的帧速率的新wave文件.

但无法解决问题.

请提出建议.

预先感谢

推荐答案

哇!

如果在增加或减小速度时不必更改音高,则只需更改采样率即可!

if you no matter to change the pitch when you increase or decrease the speed, you can just change the sample rate !

使用python可以非常简单:

Can be very simple using python:

import wave

CHANNELS = 1
swidth = 2
Change_RATE = 2

spf = wave.open('VOZ.wav', 'rb')
RATE=spf.getframerate()
signal = spf.readframes(-1)

wf = wave.open('changed.wav', 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(swidth)
wf.setframerate(RATE*Change_RATE)
wf.writeframes(signal)
wf.close()

增加或减少变量Change_RATE

现在,如果您需要保持音高不变,则需要执行相同类型的重叠添加方法!

Now if you need keep the pitch untouched, you need do same type of overlap-add method !

这篇关于增加/减少WAV文件Python的播放速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆