Update app.py
Browse files
app.py
CHANGED
|
@@ -11,34 +11,37 @@ def hello():
|
|
| 11 |
|
| 12 |
@app.route('/api/audio_separation', methods=['GET'])
|
| 13 |
def audio_separation():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
@app.route('/download/<filename>', methods=['GET'])
|
| 44 |
def download(filename):
|
|
|
|
| 11 |
|
| 12 |
@app.route('/api/audio_separation', methods=['GET'])
|
| 13 |
def audio_separation():
|
| 14 |
+
try:
|
| 15 |
+
# 获取MP3文件的直链地址
|
| 16 |
+
mp3_url = request.args.get('url')
|
| 17 |
+
if not mp3_url:
|
| 18 |
+
return "Error: URL parameter is required", 400
|
| 19 |
+
|
| 20 |
+
# 下载MP3文件到本地
|
| 21 |
+
response = requests.get(mp3_url)
|
| 22 |
+
mp3_filename = mp3_url.split('/')[-1] # 使用下载的文件名
|
| 23 |
+
with open("/tmp/" + mp3_filename, 'wb') as f:
|
| 24 |
+
f.write(response.content)
|
| 25 |
+
|
| 26 |
+
# 执行音频分离操作
|
| 27 |
+
subprocess.run(['python', 'separate.py', '/tmp/' + mp3_filename, '-o', '/tmp', '-m', './models/MDX_Net_Models/UVR-MDX-NET-Inst_HQ_3.onnx'])
|
| 28 |
+
|
| 29 |
+
# 生成分离后的文件名
|
| 30 |
+
vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_vocals.wav"
|
| 31 |
+
no_vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_no_vocals.wav"
|
| 32 |
+
|
| 33 |
+
# 提供文件的永久直链
|
| 34 |
+
vocals_url = f"/download/{os.path.basename(vocals_filename)}"
|
| 35 |
+
no_vocals_url = f"/download/{os.path.basename(no_vocals_filename)}"
|
| 36 |
+
|
| 37 |
+
# 返回结果
|
| 38 |
+
result = {
|
| 39 |
+
"vocals_url": vocals_url,
|
| 40 |
+
"no_vocals_url": no_vocals_url
|
| 41 |
+
}
|
| 42 |
+
return result
|
| 43 |
+
except Exception as e:
|
| 44 |
+
result = "Error: " + str(e), 500
|
| 45 |
|
| 46 |
@app.route('/download/<filename>', methods=['GET'])
|
| 47 |
def download(filename):
|