【问题标题】:extract human vocals from song从歌曲中提取人声
【发布时间】:2018-08-23 01:57:55
【问题描述】:

我的问题是关于如何使用 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")

我需要提取歌曲中的人声

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

【问题讨论】:

  • 当您说“提取”时,您的意思是“保留”还是“删除”?您的代码是减法(加法与减法相同)。
  • 我想保留人声并删除背景音乐
  • 好的,所以你的代码减去 L 和 R,这会保留背景音乐(去除人声) - 所以你应该将两个通道加在一起(即不要做相反的操作)然后你会得到人声。可能是人声在左右声道中的比例不同,所以你应该玩一下每个声道的比例 - 在 0 和 1 之间变化 b(或更实际地 0.30.7)并计算出 L* b+R*(1.0-b) 看看哪个在去除音乐/保留人声方面做得最好。
  • 或使用 Audacity 遵循本指南:manual.audacityteam.org/man/…
  • @barny,你所说的“将两个通道加在一起”是什么意思,这不会导致相同的音频文件吗?你能解释一下吗?谢谢!

标签: python algorithm audio signal-processing voice


【解决方案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)

【讨论】:

  • 生成的S_foreground如何保存?
  • @MaryamRahmaniMoghaddam 我将在答案部分编写保存新音频的代码
【解决方案2】:

这是对上述答案的cmets中提到的问题的答案:

如何保存生成的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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 2012-06-05
    • 2012-04-02
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多