如何通过librosa移调部分声音

How to transpose part of sound by librosa

例如,

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])

这段代码只导入sound.wav和变调后半部分,最后制作一个声音文件。

现在,我想做的更多了

我想只在特定的赫兹周围进行音高转换,比如 440hz=A

例如

在这种情况下,我有声音(A C E)= Am Chord

我只想围绕 A 进行音高转换,然后制作 (G C E)

我应该从哪里开始??或 librosa.effects.pitch_shift 可用于此目的???

这是移调器做不到的。移调器只是通过使声音变慢(作为变速)来改变频率,然后如果生成的声音较长,则切割一些小片段,或者相反,在较短的时候复制一些小片段。正如您所想象的,这个过程将整个波作为一个单一的事物来处理,这意味着频谱被完全转置。

做你想做的事情需要一种更复杂的技术,称为 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,它似乎有一个 python 模块。