I need any python library to change pitch of my wav file without any raw audio data processing. I spent couple hours to find it, but only found some strange raw data processing code snippets and video, that shows real-time pitch shift, but without source code.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- Can we recover audio from MFCC coefficients?
- How to get the background from multiple images by
- Evil ctypes hack in python
I recommend trying Librosa's pitch shift function: https://librosa.github.io/librosa/generated/librosa.effects.pitch_shift.html
Since a
wav
file basically is raw audio data, you won't be able to change the pitch without "raw audio processing".Here is what you could do. You will need the
wave
(standard library) andnumpy
modules.Open the files.
The sound should be processed in small fractions of a second. This cuts down on reverb. Try setting
fr
to 1; you'll hear annoying echos.Read the data, split it in left and right channel (assuming a stereo WAV file).
Extract the frequencies using the Fast Fourier Transform built into numpy.
Roll the array to increase the pitch.
The highest frequencies roll over to the lowest ones. That's not what we want, so zero them.
Now use the inverse Fourier transform to convert the signal back into amplitude.
Combine the two channels.
Write the output data.
Close the files when all frames are processed.
You can try pydub for quick and easy pitch change across entire audio file and for different formats (wav, mp3 etc).
Here is a working code. Inspiration from here and refer here for more details on pitch change.