从歌曲中提取人声

时间:2018-03-14 13:47:06

标签: python algorithm audio signal-processing voice

我的问题是如何使用语言python在音乐中提取人声 我已经完成了这段代码,但它提取了背景音乐

from pydub import AudioSegment
from pydub.playback import play

# read in audio file and get the two mono tracks
sound_stereo = AudioSegment.from_file(myAudioFile, format="mp3")
sound_monoL = sound_stereo.split_to_mono()[0]
sound_monoR = sound_stereo.split_to_mono()[1]

# Invert phase of the Right audio file
sound_monoR_inv = sound_monoR.invert_phase()

# Merge two L and R_inv files, this cancels out the centers
sound_CentersOut = sound_monoL.overlay(sound_monoR_inv)

# Export merged audio file
fh = sound_CentersOut.export(myAudioFile_CentersOut, format="mp3")

我需要在歌曲中提取人声

如果不是,那么如何从另一个音频文件中减去一个音频文件

3 个答案:

答案 0 :(得分:5)

您始终可以使用librosa库,该库是python中音频处理的常用库。 有助于将人声(和其他零星的前景信号)与随附的乐器分开。

https://librosa.github.io/librosa_gallery/auto_examples/plot_vocal_separation.html

它需要切片并绘制相同的切片,但分为前景和背景

答案 1 :(得分:3)

这是对以上答案的评论中提到的问题的答案:

如何保存生成的S_foreground? @MaryamRahmaniMoghaddam

首先,导入 librosa 软件包的输出模块:

import librosa.output

然后,在python文件的末尾添加以下代码:

new_y = librosa.istft(S_foreground*phase)
librosa.output.write_wav("./new-audio.wav", new_y, sr)


我引用的python文件可在此网站的末尾访问: https://librosa.github.io/librosa_gallery/auto_examples/plot_vocal_separation.html

答案 2 :(得分:1)

你可以随时使用 librosa 库,这是一个很好的 Python 音频处理库。它有助于将人声(和其他零星的前景信号)与伴奏的乐器分开。

https://librosa.github.io/librosa_gallery/auto_examples/plot_vocal_separation.html

它采用切片并绘制相同的切片,但分为前景和背景

要保存提取的前景,您可以使用:

import librosa.output
new_y = librosa.istft(S_foreground*phase)
librosa.output.write_wav("./new-audio.wav", new_y, sr)
相关问题