[英]python librosa package - How can I extract audio from spectrum
In case of vocal separation using Librosa<\/a> , the vocal and background music can be plotted separately but I want to extract the audio from vocal part and the spectrum of vocal part is located in a variable named 'S_foreground' (please visit the above link for demonstration).在使用Librosa<\/a>进行人声分离的情况下,可以单独绘制人声和背景音乐,但我想从人声部分提取音频,人声部分的频谱位于名为“S_foreground”的变量中(请访问上面的链接进行演示)。 How can I get the foreground (vocal) audio?如何获得前景(人声)音频?
" You may have noticed that S_foreground
comes from S_full
which comes from a function called magphase
. 您可能已经注意到S_foreground
来自S_full
,它来自一个名为magphase
的函数。 According to the document about this function, it can 根据有关此功能的文件,它可以
Separate a complex-valued spectrogram D into its magnitude (S) and phase (P) components, so that D = S * P. 将复值谱图D分离为其幅度(S)和相位(P)分量,使得D = S * P.
Since the actual parameter taken by magphase
in 由于magphase
采取的实际参数
S_full, phase = librosa.magphase(librosa.stft(y))
is stft(y)
, which is the Short-Time Fourier Transform of y
, the initial ndarray
, I reckon what you need to do is to calculate a new D
: 是stft(y)
这是短时傅立叶变换的y
,初始ndarray
,我想你需要做的是计算一个新的D
:
D_foreground = S_foreground * phase
And throw it to the Inverse stft function ( librosa.istft
): 并将其抛给Inverse stft函数( librosa.istft
):
y_foreground = librosa.istft(D_foreground)
After that, you can use the output function: 之后,您可以使用输出功能:
librosa.output.write_wav(output_file_path, y_foreground, sr)
To be honest, I am not familiar with these theoretical things (my poor output quality using this method might be a proof), but above is my guess on how you should export your audio. 说实话,我不熟悉这些理论上的东西(使用这种方法的输出质量差可能是一个证明),但上面我猜测你应该如何导出你的音频。 It turns out that the fidelity is very poor (at least in my case), so you might want to try some other software out if you really care about the audio quality. 事实证明,保真度非常差(至少在我的情况下),所以如果你真的关心音频质量,你可能想尝试其他一些软件。
the answer of @Alioth is working except: @Alioth 的答案是有效的,除了:
librosa.output.write_wav(output_file_path, y_foreground, sr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.