问题
In case of vocal separation using Librosa, 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). How can I get the foreground (vocal) audio?
回答1:
You may have noticed that S_foreground
comes from S_full
which comes from a function called 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.
Since the actual parameter taken by magphase
in
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
:
D_foreground = S_foreground * phase
And throw it to the Inverse stft function (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.
来源:https://stackoverflow.com/questions/48730097/python-librosa-package-how-can-i-extract-audio-from-spectrum