日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

免费背景音人声分离解决方案MVSEP-MDX23,足以和Spleeter分庭抗礼

發布時間:2023/12/29 windows 44 coder
生活随笔 收集整理的這篇文章主要介紹了 免费背景音人声分离解决方案MVSEP-MDX23,足以和Spleeter分庭抗礼 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在音視頻領域,把已經發布的混音歌曲或者音頻文件逆向分離一直是世界性的課題。音波混合的物理特性導致在沒有原始工程文件的情況下,將其還原和分離是一件很有難度的事情。

言及背景音人聲分離技術,就不能不提Spleeter,它是一種用于音頻源分離(音樂分離)的開源深度學習算法,由Deezer研究團隊開發。使用的是一個性能取向的音源分離算法,并且為用戶提供了已經預訓練好的模型,能夠開箱即用,這也是Spleeter泛用性高的原因之一,關于Spleeter,請移步:人工智能AI庫Spleeter免費人聲和背景音樂分離實踐(Python3.10),這里不再贅述。

MVSEP-MDX23背景音人聲分離技術由Demucs研發,Demucs來自Facebook Research團隊,它的發源晚于Spleeter,早于MDX-Net,并且經歷過4個大版本的迭代,每一代的模型結構都被大改。Demucs的生成質量從v3開始大幅質變,一度領先行業平均水平,v4是現在最強的開源樂器分離單模型,v1和v2的網絡模型被用作MDX-net其中的一部分。

本次我們基于MVSEP-MDX23來對音頻的背景音和人聲進行分離。

本地分離人聲和背景音

如果本地離線運行MVSEP-MDX23,首先克隆代碼:

git clone https://github.com/jarredou/MVSEP-MDX23-Colab_v2.git

隨后進入項目并安裝依賴:

cd MVSEP-MDX23-Colab_v2  
pip3 install -r requirements.txt

隨后直接進推理即可:

python3 inference.py --input_audio test.wav --output_folder ./results/

這里將test.wav進行人聲分離,分離后的文件在results文件夾生成。

注意推理過程中會將分離模型下載到項目的models目錄,極其巨大。

同時推理過程相當緩慢。

這里可以添加--single_onnx參數來提高推理速度,但音質上有一定的損失。

如果本地設備具備12G以上的顯存,也可以添加--large_gpu參數來提高推理的速度。

如果本地沒有N卡或者顯存實在捉襟見肘,也可以通過--cpu參數來使用cpu進行推理,但是并不推薦這樣做,因為本來就慢,用cpu就更慢了。

令人暖心的是,官方還利用Pyqt寫了一個小的gui界面來提高操作友好度:

__author__ = 'Roman Solovyev (ZFTurbo), IPPM RAS'  
  
if __name__ == '__main__':  
    import os  
  
    gpu_use = "0"  
    print('GPU use: {}'.format(gpu_use))  
    os.environ["CUDA_VISIBLE_DEVICES"] = "{}".format(gpu_use)  
  
import time  
import os  
import numpy as np  
from PyQt5.QtCore import *  
from PyQt5 import QtCore  
from PyQt5.QtWidgets import *  
import sys  
from inference import predict_with_model  
  
  
root = dict()  
  
  
class Worker(QObject):  
    finished = pyqtSignal()  
    progress = pyqtSignal(int)  
  
    def __init__(self, options):  
        super().__init__()  
        self.options = options  
  
    def run(self):  
        global root  
        # Here we pass the update_progress (uncalled!)  
        self.options['update_percent_func'] = self.update_progress  
        predict_with_model(self.options)  
        root['button_start'].setDisabled(False)  
        root['button_finish'].setDisabled(True)  
        root['start_proc'] = False  
        self.finished.emit()  
  
    def update_progress(self, percent):  
        self.progress.emit(percent)  
  
  
class Ui_Dialog(object):  
    def setupUi(self, Dialog):  
        global root  
  
        Dialog.setObjectName("Settings")  
        Dialog.resize(370, 180)  
  
        self.checkbox_cpu = QCheckBox("Use CPU instead of GPU?", Dialog)  
        self.checkbox_cpu.move(30, 10)  
        self.checkbox_cpu.resize(320, 40)  
        if root['cpu']:  
            self.checkbox_cpu.setChecked(True)  
  
        self.checkbox_single_onnx = QCheckBox("Use single ONNX?", Dialog)  
        self.checkbox_single_onnx.move(30, 40)  
        self.checkbox_single_onnx.resize(320, 40)  
        if root['single_onnx']:  
            self.checkbox_single_onnx.setChecked(True)  
  
        self.pushButton_save = QPushButton(Dialog)  
        self.pushButton_save.setObjectName("pushButton_save")  
        self.pushButton_save.move(30, 120)  
        self.pushButton_save.resize(150, 35)  
  
        self.pushButton_cancel = QPushButton(Dialog)  
        self.pushButton_cancel.setObjectName("pushButton_cancel")  
        self.pushButton_cancel.move(190, 120)  
        self.pushButton_cancel.resize(150, 35)  
  
        self.retranslateUi(Dialog)  
        QtCore.QMetaObject.connectSlotsByName(Dialog)  
        self.Dialog = Dialog  
  
        # connect the two functions  
        self.pushButton_save.clicked.connect(self.return_save)  
        self.pushButton_cancel.clicked.connect(self.return_cancel)  
  
    def retranslateUi(self, Dialog):  
        _translate = QtCore.QCoreApplication.translate  
        Dialog.setWindowTitle(_translate("Settings", "Settings"))  
        self.pushButton_cancel.setText(_translate("Settings", "Cancel"))  
        self.pushButton_save.setText(_translate("Settings", "Save settings"))  
  
    def return_save(self):  
        global root  
        # print("save")  
        root['cpu'] = self.checkbox_cpu.isChecked()  
        root['single_onnx'] = self.checkbox_single_onnx.isChecked()  
        self.Dialog.close()  
  
    def return_cancel(self):  
        global root  
        # print("cancel")  
        self.Dialog.close()  
  
  
class MyWidget(QWidget):  
    def __init__(self):  
        super().__init__()  
        self.initUI()  
  
    def initUI(self):  
        self.resize(560, 360)  
        self.move(300, 300)  
        self.setWindowTitle('MVSEP music separation model')  
        self.setAcceptDrops(True)  
  
    def dragEnterEvent(self, event):  
        if event.mimeData().hasUrls():  
            event.accept()  
        else:  
            event.ignore()  
  
    def dropEvent(self, event):  
        global root  
        files = [u.toLocalFile() for u in event.mimeData().urls()]  
        txt = ''  
        root['input_files'] = []  
        for f in files:  
            root['input_files'].append(f)  
            txt += f + '\n'  
        root['input_files_list_text_area'].insertPlainText(txt)  
        root['progress_bar'].setValue(0)  
  
    def execute_long_task(self):  
        global root  
  
        if len(root['input_files']) == 0 and 1:  
            QMessageBox.about(root['w'], "Error", "No input files specified!")  
            return  
  
        root['progress_bar'].show()  
        root['button_start'].setDisabled(True)  
        root['button_finish'].setDisabled(False)  
        root['start_proc'] = True  
  
        options = {  
            'input_audio': root['input_files'],  
            'output_folder': root['output_folder'],  
            'cpu': root['cpu'],  
            'single_onnx': root['single_onnx'],  
            'overlap_large': 0.6,  
            'overlap_small': 0.5,  
        }  
  
        self.update_progress(0)  
        self.thread = QThread()  
        self.worker = Worker(options)  
        self.worker.moveToThread(self.thread)  
  
        self.thread.started.connect(self.worker.run)  
        self.worker.finished.connect(self.thread.quit)  
        self.worker.finished.connect(self.worker.deleteLater)  
        self.thread.finished.connect(self.thread.deleteLater)  
        self.worker.progress.connect(self.update_progress)  
  
        self.thread.start()  
  
    def stop_separation(self):  
        global root  
        self.thread.terminate()  
        root['button_start'].setDisabled(False)  
        root['button_finish'].setDisabled(True)  
        root['start_proc'] = False  
        root['progress_bar'].hide()  
  
    def update_progress(self, progress):  
        global root  
        root['progress_bar'].setValue(progress)  
  
    def open_settings(self):  
        global root  
        dialog = QDialog()  
        dialog.ui = Ui_Dialog()  
        dialog.ui.setupUi(dialog)  
        dialog.exec_()  
  
  
def dialog_select_input_files():  
    global root  
    files, _ = QFileDialog.getOpenFileNames(  
        None,  
        "QFileDialog.getOpenFileNames()",  
        "",  
        "All Files (*);;Audio Files (*.wav, *.mp3, *.flac)",  
    )  
    if files:  
        txt = ''  
        root['input_files'] = []  
        for f in files:  
            root['input_files'].append(f)  
            txt += f + '\n'  
        root['input_files_list_text_area'].insertPlainText(txt)  
        root['progress_bar'].setValue(0)  
    return files  
  
  
def dialog_select_output_folder():  
    global root  
    foldername = QFileDialog.getExistingDirectory(  
        None,  
        "Select Directory"  
    )  
    root['output_folder'] = foldername + '/'  
    root['output_folder_line_edit'].setText(root['output_folder'])  
    return foldername  
  
  
def create_dialog():  
    global root  
    app = QApplication(sys.argv)  
  
    w = MyWidget()  
  
    root['input_files'] = []  
    root['output_folder'] = os.path.dirname(os.path.abspath(__file__)) + '/results/'  
    root['cpu'] = False  
    root['single_onnx'] = False  
  
    button_select_input_files = QPushButton(w)  
    button_select_input_files.setText("Input audio files")  
    button_select_input_files.clicked.connect(dialog_select_input_files)  
    button_select_input_files.setFixedHeight(35)  
    button_select_input_files.setFixedWidth(150)  
    button_select_input_files.move(30, 20)  
  
    input_files_list_text_area = QTextEdit(w)  
    input_files_list_text_area.setReadOnly(True)  
    input_files_list_text_area.setLineWrapMode(QTextEdit.NoWrap)  
    font = input_files_list_text_area.font()  
    font.setFamily("Courier")  
    font.setPointSize(10)  
    input_files_list_text_area.move(30, 60)  
    input_files_list_text_area.resize(500, 100)  
  
    button_select_output_folder = QPushButton(w)  
    button_select_output_folder.setText("Output folder")  
    button_select_output_folder.setFixedHeight(35)  
    button_select_output_folder.setFixedWidth(150)  
    button_select_output_folder.clicked.connect(dialog_select_output_folder)  
    button_select_output_folder.move(30, 180)  
  
    output_folder_line_edit = QLineEdit(w)  
    output_folder_line_edit.setReadOnly(True)  
    font = output_folder_line_edit.font()  
    font.setFamily("Courier")  
    font.setPointSize(10)  
    output_folder_line_edit.move(30, 220)  
    output_folder_line_edit.setFixedWidth(500)  
    output_folder_line_edit.setText(root['output_folder'])  
  
    progress_bar = QProgressBar(w)  
    # progress_bar.move(30, 310)  
    progress_bar.setValue(0)  
    progress_bar.setGeometry(30, 310, 500, 35)  
    progress_bar.setAlignment(QtCore.Qt.AlignCenter)  
    progress_bar.hide()  
    root['progress_bar'] = progress_bar  
  
    button_start = QPushButton('Start separation', w)  
    button_start.clicked.connect(w.execute_long_task)  
    button_start.setFixedHeight(35)  
    button_start.setFixedWidth(150)  
    button_start.move(30, 270)  
  
    button_finish = QPushButton('Stop separation', w)  
    button_finish.clicked.connect(w.stop_separation)  
    button_finish.setFixedHeight(35)  
    button_finish.setFixedWidth(150)  
    button_finish.move(200, 270)  
    button_finish.setDisabled(True)  
  
    button_settings = QPushButton('?', w)  
    button_settings.clicked.connect(w.open_settings)  
    button_settings.setFixedHeight(35)  
    button_settings.setFixedWidth(35)  
    button_settings.move(495, 270)  
    button_settings.setDisabled(False)  
  
    mvsep_link = QLabel(w)  
    mvsep_link.setOpenExternalLinks(True)  
    font = mvsep_link.font()  
    font.setFamily("Courier")  
    font.setPointSize(10)  
    mvsep_link.move(415, 30)  
    mvsep_link.setText('Powered by <a )  
  
    root['w'] = w  
    root['input_files_list_text_area'] = input_files_list_text_area  
    root['output_folder_line_edit'] = output_folder_line_edit  
    root['button_start'] = button_start  
    root['button_finish'] = button_finish  
    root['button_settings'] = button_settings  
  
    # w.showMaximized()  
    w.show()  
    sys.exit(app.exec_())  
  
  
if __name__ == '__main__':  
    create_dialog()

效果如下:

界面雖然樸素,但相當實用,Spleeter可沒給我們提供這個待遇。

Colab云端分離人聲和背景音

托Google的福,我們也可以在Colab云端使用MVSEP-MDX23:

https://colab.research.google.com/github/jarredou/MVSEP-MDX23-Colab_v2/blob/v2.3/MVSep-MDX23-Colab.ipynb#scrollTo=uWX5WOqjU0QC

首先安裝MVSEP-MDX23:

#@markdown #Installation  
#@markdown *Run this cell to install MVSep-MDX23*  
print('Installing... This will take 1 minute...')  
%cd /content  
from google.colab import drive  
drive.mount('/content/drive')  
!git clone https://github.com/jarredou/MVSEP-MDX23-Colab_v2.git &> /dev/null  
%cd /content/MVSEP-MDX23-Colab_v2  
!pip install -r requirements.txt &> /dev/null  
# onnxruntime-gpu nightly fix for cuda12.2  
!python -m pip install ort-nightly-gpu --index-url=https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ort-cuda-12-nightly/pypi/simple/  
print('Installation done !')

隨后編寫推理代碼:

#@markdown #Separation  
from pathlib import Path  
import glob  
  
%cd /content/MVSEP-MDX23-Colab_v2  
  
  
input = '/content/drive/MyDrive' #@param {type:"string"}  
output_folder = '/content/drive/MyDrive/output' #@param {type:"string"}  
#@markdown ---  
#@markdown *Bigshifts=1 to disable that feature*  
  
BigShifts = 7 #@param {type:"slider", min:1, max:41, step:1}  
#@markdown ---  
overlap_InstVoc = 1 #@param {type:"slider", min:1, max:40, step:1}  
overlap_VitLarge = 1 #@param {type:"slider", min:1, max:40, step:1}  
#@markdown ---  
weight_InstVoc = 8 #@param {type:"slider", min:0, max:10, step:1}  
weight_VitLarge = 5 #@param {type:"slider", min:0, max:10, step:1}  
#@markdown ---  
use_VOCFT = False #@param {type:"boolean"}  
overlap_VOCFT = 0.1 #@param {type:"slider", min:0, max:0.95, step:0.05}  
weight_VOCFT = 2 #@param {type:"slider", min:0, max:10, step:1}  
#@markdown ---  
vocals_instru_only = True #@param {type:"boolean"}  
overlap_demucs = 0.6 #@param {type:"slider", min:0, max:0.95, step:0.05}  
#@markdown ---  
output_format = 'PCM_16' #@param ["PCM_16", "FLOAT"]  
if vocals_instru_only:  
    vocals_only = '--vocals_only true'  
else:  
    vocals_only = ''  
  
  
if use_VOCFT:  
    use_VOCFT = '--use_VOCFT true'  
else:  
    use_VOCFT = ''  
  
if Path(input).is_file():  
  file_path = input  
  Path(output_folder).mkdir(parents=True, exist_ok=True)  
  !python inference.py \  
        --large_gpu \  
        --weight_InstVoc {weight_InstVoc} \  
        --weight_VOCFT {weight_VOCFT} \  
        --weight_VitLarge {weight_VitLarge} \  
        --input_audio "{file_path}" \  
        --overlap_demucs {overlap_demucs} \  
        --overlap_VOCFT {overlap_VOCFT} \  
        --overlap_InstVoc {overlap_InstVoc} \  
        --overlap_VitLarge {overlap_VitLarge} \  
        --output_format {output_format} \  
        --BigShifts {BigShifts} \  
        --output_folder "{output_folder}" \  
        {vocals_only} \  
        {use_VOCFT}  
  
else:  
  file_paths = sorted([f'"{glob.escape(path)}"' for path in glob.glob(input + "/*")])[:]  
  input_audio_args = ' '.join(file_paths)  
  Path(output_folder).mkdir(parents=True, exist_ok=True)  
  !python inference.py \  
          --large_gpu \  
          --weight_InstVoc {weight_InstVoc} \  
          --weight_VOCFT {weight_VOCFT} \  
          --weight_VitLarge {weight_VitLarge} \  
          --input_audio {input_audio_args} \  
          --overlap_demucs {overlap_demucs} \  
          --overlap_VOCFT {overlap_VOCFT} \  
          --overlap_InstVoc {int(overlap_InstVoc)} \  
          --overlap_VitLarge {int(overlap_VitLarge)} \  
          --output_format {output_format} \  
          --BigShifts {BigShifts} \  
          --output_folder "{output_folder}" \  
          {vocals_only} \  
          {use_VOCFT}

這里默認使用google云盤的目錄,也可以修改為當前服務器的目錄地址。

結語

MVSEP-MDX23 和 Spleeter 都是音頻人聲背景音分離軟件,作為用戶,我們到底應該怎么選擇?

MVSEP-MDX23 基于 Demucs4 和 MDX 神經網絡架構,可以將音樂分離成“bass”、“drums”、“vocals”和“other”四個部分。MVSEP-MDX23 在 2023 年的音樂分離挑戰中獲得了第三名,并且在 MultiSong 數據集上的質量比較中表現出色。它提供了 Python 命令行工具和 GUI 界面,支持 CPU 和 GPU 加速,可以在本地運行。

Spleeter 是由 Deezer 開發的開源音頻分離庫,它使用深度學習模型將音頻分離成不同的音軌,如人聲、伴奏等。Spleeter 提供了預訓練的模型,可以在命令行或作為 Python 庫使用。它的優勢在于易用性和靈活性,可以根據需要分離不同數量的音軌。

總的來說,MVSEP-MDX23 在音頻分離的性能和精度上表現出色,尤其適合需要高質量音頻分離的專業用戶。而 Spleeter 則更適合普通用戶和開發者,因為它易于使用,并且具有更多的定制選項。

總結

以上是生活随笔為你收集整理的免费背景音人声分离解决方案MVSEP-MDX23,足以和Spleeter分庭抗礼的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。