1

For example,

y, sr = librosa.load("sound.wav",sr=44100,mono=True)

half = int(y.shape / 2)
y1 = y[:half]
y2 = y[half:]
y_pit= librosa.effects.pitch_shift(y2, sr, n_steps=24)
y = np.concatenate([y1,y_pit])

This code imports sound.wav and pitch-shift only the later half ,then finally makes one sound file.

Now, what I want to do is more.

I would like to pitch-shift only around specific hz like 440hz=A

For example

In the case, I have sound (A C E) = Am Chord

I want to pitch shift only around A then make (G C E)

Where should I start ?? or librosa.effects.pitch_shift is useful for this purpose???

whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

1

This is not possible with a pitch shifter. A pitch shifter simply changes the frequencies by slowing the sound up or down (as a varispeed) then cutting some small slices if the resulting sound is longer or, at the contrary, duplicating some small slices while it is shorter. As you can imagine, this process handles the whole wave as a single thing meaning that the spectrum is completely transposed.

Doing what you want requires a much more sophisticated technique called resynthesis which first converts the wave in a synthetic sound using FFT and additive synthesis (or other techniques more appropriate when the sound is noisy), then allows some manipulation on independent parts of the spectrum, and finally reconverts the synthetic sound to an audio wave. There is a standalone software doing that quite well which is called Spear. You could also investigate Loris which seems to have a python module.

dspr
  • 2,383
  • 2
  • 15
  • 19
  • Thank you very much for your comment. `librosa` also has STFT convert function, it gives the 2-dimensional shape (Hz, each frame). I have one more simple question, I might be able to change the certain frequency by librosa or some manual way, is there any idea?? – whitebear Dec 13 '20 at 13:50
  • I don't have the practice of Librosa myself (I'm more focused on C/C++ currently for performance reasons). But anyway these technologies are not easy to manipulate because, when you transpose a note, you don't necessarily transpose its overtones. It can produce interesting results, but not necessarily those you expect... If you are looking for a relatively 'natural' result, you should transpose, not only the fundamental frequency, but also a few of its first harmonics at least (Hz x2, x3, x4, etc.). Good luck ! – dspr Dec 13 '20 at 21:31
  • Thank you very much. I have tried to move data from just around 440hz to upper, as you told, it doesn't show the good result. I will try to move x2, x3, x4 as well and see what happens.. Thanks to your hint. I can try and error. – whitebear Dec 14 '20 at 04:16