2b-studio / tests /test_daw.py
2Btainment's picture
2B-Studio: DAW-Studio, neue Modelle (YuE2, TangoFlux, AudioGen, AudioLDM2), Lizenz-Badges, HF-Login, Einswarm Schwarz/Gold
c600f78 verified
Raw History Blame Contribute Delete
1.68 kB
import json
import numpy as np
import pytest
from studio.daw import api, engine
SR = 48000
def _tone(seconds=2.0):
t = np.arange(int(SR * seconds)) / SR
x = (0.3 * np.sin(2 * np.pi * 220 * t)).astype(np.float32)
return np.vstack([x, x])
@pytest.mark.parametrize("effect", sorted(engine.EFFECTS))
def test_effects_produce_audio(effect):
out, eng = engine.apply_effect(_tone(), SR, effect, {})
assert out.shape[0] == 2 and out.shape[1] > SR and np.isfinite(out).all() and eng
def test_lufs_target():
out, _ = engine.apply_effect(_tone(3), SR, "lufs", {"target": -16})
assert abs(engine.lufs(out, SR) + 16) < 0.6
def test_generate_procedural_and_project_roundtrip(tmp_path):
res = json.loads(api.daw_generate("sfx", "procedural", "impact", "", "", 2, 120, "", 0, None))
assert res["duration_s"] == 2.0 and res["badge"] == "free"
proj = {"tracks": [], "clips": [], "assets": [{"id": "a1", "name": "x", "path": res["path"]}]}
saved = json.loads(api.daw_save(json.dumps(proj), "Test", None, None))
loaded = json.loads(api.daw_load(saved["path"]))
assert loaded["assets"][0]["url"].startswith("/gradio_api/file=")
def test_path_guard():
with pytest.raises(Exception):
api.daw_fx("/etc/passwd", "gain", "{}", 0, 0)
def test_catalog_lists_license_badges():
cat = json.loads(api.daw_catalog())
ids = {e["id"] for e in cat["elements"]}
assert {"full_song", "voice", "drums", "bass", "instrument", "instrumental_song", "melody_solo",
"melody_ensemble", "sfx", "transition"} <= ids
badges = {m["badge"] for e in cat["elements"] for m in e["models"]}
assert {"free", "nc"} <= badges