Update Readme.md
Browse filesCreate a Separator object using the 2stems pre-trained model (vocals and accompaniment) to generate Python 3.12 code for separating vocals and instrumental tracks from an MP3 file
# 创建一个Separator对象,使用2stems预训练模型(vocals 和 accompaniment),用python 3.12生成一个分离MP3文件人声和伴奏的代码
README.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- HuggingFaceFW/fineweb-edu
|
5 |
+
language:
|
6 |
+
- aa
|
7 |
+
metrics:
|
8 |
+
- accuracy
|
9 |
+
library_name: adapter-transformers
|
10 |
+
tags:
|
11 |
+
- music
|
12 |
+
---
|
13 |
+
pip install spleeter
|
14 |
+
|
15 |
+
import os
|
16 |
+
from spleeter.separator import Separator
|
17 |
+
from spleeter.audio.adapter import AudioAdapter
|
18 |
+
|
19 |
+
def separate_vocals(input_file, output_dir):
|
20 |
+
# 创建一个Separator对象,使用2stems预训练模型(vocals 和 accompaniment)
|
21 |
+
separator = Separator('spleeter:2stems')
|
22 |
+
|
23 |
+
# 创建输出目录(如果不存在)
|
24 |
+
os.makedirs(output_dir, exist_ok=True)
|
25 |
+
|
26 |
+
# 执行分离
|
27 |
+
separator.separate_to_file(input_file, output_dir)
|
28 |
+
|
29 |
+
print(f"分离完成。结果保存在 {output_dir}")
|
30 |
+
|
31 |
+
# 使用示例
|
32 |
+
if __name__ == "__main__":
|
33 |
+
input_mp3 = "path/to/your/input.mp3" # 替换为你的MP3文件路径
|
34 |
+
output_directory = "path/to/output/directory" # 替换为你想要保存输出的目录
|
35 |
+
|
36 |
+
separate_vocals(input_mp3, output_directory)
|