Files
SoundGame Dev f0f0a9b50e 初始提交:3 款纯音频游戏 + 共享引擎 + 完整文档与资产管线
- 共享引擎(app/src/main):GestureEngine 6 手势识别、AudioEngine 三层音频
  (ExoPlayer BGM 交叉淡入 / 对白 ducking / SoundPool 低延迟)、Game/GameEngine
  状态机接口、MainActivity 全屏封面 + TalkBack
- 《声命线》storyline:末世互动广播剧,3 幕 8 抉择点 4 结局
- 《声东击西》reflex:听声辨位反应,12 波战斗 + BGM 三档 BPM 变速
- 《暗室》escape:3x3 网格密室逃脱,钥匙→铁柜→保险丝→电箱→大门谜题链
- 文档:setup(从零搭建)/ architecture(架构)/ engine-api(引擎 API)/
  asset-pipeline(资产流水线)/ games/*(三款游戏设计文档)
- 资产管线:Qwen3-TTS 对白 + 程序合成音效/BGM + Mureka BGM 的 gen 脚本与台账,
  全部 ogg 资产入库可复现
- env.d 环境脚本:android/tts 入库;sfx/mureka 含密钥不入库,仅提交 .example.sh 模板
2026-08-29 13:00:34 +08:00

74 lines
2.6 KiB
Python

"""Shared helpers for the build scripts: GPU arch detection + output paths.
Every builder writes its TRT engine to:
../models/<arch>/<engine_subdir>/<file>.trt
where <arch> is the sm_XX compute capability of the GPU you're building on
(TensorRT bakes the arch into the engine, so the arch you build on IS the
arch the engine runs on).
"""
import os
import subprocess
def detect_arch() -> str:
"""Compute capability of the current GPU as 'sm_XX' (e.g., 'sm_90').
Reads nvidia-smi. Falls back to 'sm_90' if no GPU is visible (the build
will fail anyway, but you get a clearer error from TensorRT than from us).
"""
try:
out = subprocess.check_output(
["nvidia-smi", "--query-gpu=compute_cap", "--format=csv,noheader,nounits"],
stderr=subprocess.DEVNULL, timeout=5,
).decode().strip().splitlines()
if out:
return f"sm_{out[0].strip().replace('.', '')}"
except Exception:
pass
return "sm_90"
def repo_root() -> str:
"""Path to the optimized/tensorRT/ directory (parent of build/)."""
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def arch_dir(arch: str = None) -> str:
"""Resolve the per-arch output dir for engines: ../models/<arch>/."""
if arch is None:
arch = detect_arch()
d = os.path.join(repo_root(), "models", arch)
os.makedirs(d, exist_ok=True)
return d
def onnx_dir(engine_subdir: str = None) -> str:
"""ONNX output dir. ONNX is arch-independent — the same .onnx file can be
compiled into a .trt engine for any TRT-supported GPU.
Resolution order:
1. $SA3_ONNX_DIR (override; used by automation)
2. ../../../../stable-audio-3-optimized/onnx/ — the HF model repo when
checked out as a sibling of stable-audio-3 (canonical layout: github
repo = code, HF repo = ONNX + TRT artifacts)
3. <github_repo>/optimized/tensorRT/onnx/ — local fallback when no
HF clone is around (a working area; not git-tracked here)
"""
override = os.environ.get("SA3_ONNX_DIR")
if override:
d = override
else:
# repo_root() = .../stable-audio-3/optimized/tensorRT
# HF sibling = .../stable-audio-3-optimized
github_root = os.path.dirname(os.path.dirname(os.path.dirname(repo_root())))
hf_sibling = os.path.join(github_root, "stable-audio-3-optimized", "onnx")
if os.path.isdir(os.path.dirname(hf_sibling)):
d = hf_sibling
else:
d = os.path.join(repo_root(), "onnx")
if engine_subdir:
d = os.path.join(d, engine_subdir)
os.makedirs(d, exist_ok=True)
return d