I need help with a project which consists of 2 parts:
- real time pitch shifter in python (from scratch).
- switch the pitches of 2 voices from 2 different speakers.
I have 2 questions:
- I couldn't find the proper math behind pitch shifting to implement it from scratch so a simple explanation would be appreciated.
- Do I need to extract pitches from 2 voices to switch them or there's a simpler solution? If not an explanation on how to properly extract pitch from a sound and switching it is appreciated.
Thanks in advance.
librosa
does this. The source is athttps://github.com/librosa/librosa/blob/main/librosa/effects.py#L253
The algorithm used there is summarised by the comment,
To explain this a little more, you can change the pitch by "stretching out" (or squashing) the waveform in the horizontal direction. This would, for example, make the vibrations of Middle C (262 Hz) be further apart and thus lower in frequency -- and, as a result, also lower in pitch. Stretching it out to double (and then filling in samples so that the sample rate remains unchanged) would change the pitch down an octave to C3 at 131Hz.
It looks like the hard part is resampling effectively, but a variety of algorithms are mentioned in the code.