- 7 大维度分析器: 节奏/可舞性/能量/情绪/调性/音色/音频质量 - 6 种场景配置: pop/classical/electronic/rock/jazz/hiphop - 4 个 API: scenes/dimensions/config/evaluate - 基于 librosa 的纯算法分析(CPU 即可运行) - nginx IP 白名单认证(无 RBAC)
33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
"""POST /api/evaluate.dspy — 歌曲评估"""
|
||
import json
|
||
import os
|
||
import tempfile
|
||
from songrate.evaluator import evaluate_song
|
||
|
||
# 获取参数
|
||
scene = params_kw.get('scene', 'pop')
|
||
filepath = params_kw.get('filepath', '')
|
||
|
||
# 如果没有 filepath,检查是否有上传文件
|
||
if not filepath:
|
||
# 支持 multipart/form-data 上传
|
||
file_content = params_kw.get('file_content', '')
|
||
filename = params_kw.get('filename', '')
|
||
if file_content and filename:
|
||
ext = os.path.splitext(filename)[1] or '.mp3'
|
||
filepath = os.path.join(tempfile.gettempdir(), f'songrate_{os.getpid()}{ext}')
|
||
with open(filepath, 'wb') as f:
|
||
f.write(file_content if isinstance(file_content, bytes) else file_content.encode())
|
||
cleanup = True
|
||
else:
|
||
return json.dumps({"error": "缺少 filepath 或 file_content+filename 参数"}, ensure_ascii=False)
|
||
else:
|
||
cleanup = False
|
||
|
||
try:
|
||
result = evaluate_song(filepath, scene)
|
||
return json.dumps(result, ensure_ascii=False)
|
||
finally:
|
||
if cleanup and os.path.exists(filepath):
|
||
os.remove(filepath)
|