简体   繁体   English

增加/降低WAV文件Python的播放速度

[英]Increase/Decrease Play Speed of a WAV file Python

I want to change play speed (increase or decrease) of a certain WAV audio file using python wave module. 我想用python wave模块改变某个WAV音频文件的播放速度(增加或减少)。

I tried below thing : 我尝试下面的事情:

  1. Read frame rate of input file. 读取输入文件的帧率。
  2. Double the frame rate. 帧速率加倍。
  3. Write a new wave file with increased frame rate using output_wave.setparams() function. 使用output_wave.setparams()函数编写具有增加帧速率的新波形文件。

But its not working out. 但它没有成功。

Please suggest. 请建议。

Thanks in Advance, 提前致谢,

WOW! 哇!

if you no matter to change the pitch when you increase or decrease the speed, you can just change the sample rate ! 如果你在增加或减少速度时改变音高,你可以改变采样率!

Can be very simple using python: 使用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()

increase or decrease the variable Change_RATE ! 增加或减少变量Change_RATE

Now if you need keep the pitch untouched, you need do same type of overlap-add method ! 现在,如果你需要保持音高不变,你需要做同样类型的重叠添加方法!

If you change the sampling frequency it has no influence on audiable playback speed. 如果更改采样频率,则不会影响可听回放速度。 You can play around with this using SoX Sound eXchange, the Swiss Army knife of audio manipulation 你可以使用SoX Sound eXchange,这是瑞士军刀的音频操作

There is pySonic library for python look at UserSpeed method of the Song object. python的pySonic库看一下Song对象的UserSpeed方法。 pySonic Python wrapper of FMOD Sound library FMOD声音库的pySonic Python包装器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM