Increase/Decrease Play Speed of a WAV file Python

半世苍凉 提交于 2019-12-10 09:23:48

问题


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

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.

But its not working out.

Please suggest.

Thanks in Advance,


回答1:


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:

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 !

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




回答2:


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

There is pySonic library for python look at UserSpeed method of the Song object. pySonic Python wrapper of FMOD Sound library



来源:https://stackoverflow.com/questions/22755558/increase-decrease-play-speed-of-a-wav-file-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!