- 7 大维度分析器: 节奏/可舞性/能量/情绪/调性/音色/音频质量 - 6 种场景配置: pop/classical/electronic/rock/jazz/hiphop - 4 个 API: scenes/dimensions/config/evaluate - 基于 librosa 的纯算法分析(CPU 即可运行) - nginx IP 白名单认证(无 RBAC)
33 lines
930 B
Plaintext
33 lines
930 B
Plaintext
"""GET /api/dimensions.dspy — 获取维度树及权重"""
|
|
import json
|
|
from songrate.scenes import get_scene_config, SCENES, DIMENSIONS
|
|
|
|
scene = params_kw.get('scene', 'pop')
|
|
if scene not in SCENES:
|
|
return json.dumps({"error": f"未知场景: {scene}", "available_scenes": list(SCENES.keys())}, ensure_ascii=False)
|
|
|
|
config = get_scene_config(scene)
|
|
weights = config["weights"]
|
|
|
|
# 构建维度树
|
|
tree = []
|
|
for dim_key, dim_info in DIMENSIONS.items():
|
|
weight = weights.get(dim_key, 0)
|
|
tree.append({
|
|
"key": dim_key,
|
|
"name": dim_info["name"],
|
|
"weight": weight,
|
|
"enabled": weight > 0,
|
|
"sub_dimensions": dim_info["sub_dimensions"]
|
|
})
|
|
|
|
# 按权重排序
|
|
tree.sort(key=lambda d: d["weight"], reverse=True)
|
|
|
|
return json.dumps({
|
|
"scene": scene,
|
|
"scene_name": config["name"],
|
|
"dimensions": tree,
|
|
"total_weight": round(sum(weights.values()), 2)
|
|
}, ensure_ascii=False)
|