简体   繁体   English

"python librosa 包 - 如何从频谱中提取音频"

[英]python librosa package - How can I extract audio from spectrum

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM