SoulX-Singer-with-background / scripts /automate_example_outputs.sh
杨月政
fix: 修复 spaces 依赖导入问题
5f32b51
#!/usr/bin/env bash
# 一键:准备 venv → 安装依赖 → 生成 SVC 预生成示例 → 校验
# 用法(在任意目录执行均可):
# ./scripts/automate_example_outputs.sh
# ./scripts/automate_example_outputs.sh --skip-install
# ./scripts/automate_example_outputs.sh --skip-install -- --device cpu --index 0
# 「--」之后参数会原样传给 generate_example_outputs.py
set -euo pipefail
SPACE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$SPACE_ROOT"
SKIP_INSTALL=0
PY_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-install)
SKIP_INSTALL=1
shift
;;
--)
shift
PY_ARGS+=("$@")
break
;;
*)
PY_ARGS+=("$1")
shift
;;
esac
done
export PYTHONUNBUFFERED=1
pick_python() {
if [[ -n "${PYTHON:-}" ]] && [[ -x "${PYTHON}" ]]; then
echo "$PYTHON"
return
fi
if [[ -x "$SPACE_ROOT/.venv/bin/python" ]]; then
echo "$SPACE_ROOT/.venv/bin/python"
return
fi
if command -v python3.11 >/dev/null 2>&1; then
command -v python3.11
return
fi
command -v python3
}
if [[ ! -d "$SPACE_ROOT/.venv" ]]; then
echo "[automate] 创建 .venv ..."
if command -v python3.11 >/dev/null 2>&1; then
python3.11 -m venv "$SPACE_ROOT/.venv"
elif command -v python3 >/dev/null 2>&1; then
python3 -m venv "$SPACE_ROOT/.venv"
else
echo "错误: 未找到 python3.11 或 python3" >&2
exit 1
fi
fi
# shellcheck source=/dev/null
source "$SPACE_ROOT/.venv/bin/activate"
if [[ "$SKIP_INSTALL" -eq 0 ]]; then
echo "[automate] pip install -r requirements.txt (首次或依赖变更时较慢)..."
pip install -U pip wheel setuptools
pip install -r "$SPACE_ROOT/requirements.txt"
else
echo "[automate] 跳过 pip install(--skip-install)"
fi
echo "[automate] 生成 example/outputs/*.wav ..."
if [[ ${#PY_ARGS[@]} -eq 0 ]]; then
python -u "$SPACE_ROOT/scripts/generate_example_outputs.py"
else
python -u "$SPACE_ROOT/scripts/generate_example_outputs.py" "${PY_ARGS[@]}"
fi
echo "[automate] 校验 ..."
python "$SPACE_ROOT/scripts/verify_example_outputs.py"
echo "[automate] 全部完成。"