Files
SoundGame/tools/extract_voice_text.py
T
SoundGame Dev 79dffac01e guide层v1: 全局向导交互层落地(状态签名earcon/turn cue/静默看门狗/纠错) + 6游戏接线 + 8句向导语音 + 测试全绿
- engine/guide.js 运行时合成8个签名earcon(方法论L2硬参数),off档零定时器,插播queue不顶对白
- settings: guide三档(full/standard/off默认full) + 语速2.2视障档;audio: isVoicePlaying()/setRateBoostEnabled() 清两个已知问题
- 6游戏按schemes§2接线: storyline看门狗+无效手势纠错、simon免扣重听看门狗、escape turn cue+提前卡关提示、rhythm gd_answer/gd_miss+结算看门狗+快进豁免、space首撞指令提示+结算看门狗、rpg格挡纠错+60s催促+状态签名
- 大厅设置面板+向导文档(14-guide-layer.md)+00-global-ux §6;R5台词表补4条一致性
- 试玩转写含向导事件;6 playtest(guide=off断言零改动)+guide.test(34断言)+资产终检全绿
2026-08-30 22:46:05 +08:00

62 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""从 tools/gen_voice_dual.py 台词表提取 id -> 台词全文 映射,输出 JSON。
供试玩转写 harness(web/harness/)把语音播放事件转写成人类可读文本。
台词表是唯一事实源:新台词先改进 gen_voice_dual.py,再跑本脚本刷新 JSON。
用法:.venv-tts/bin/python tools/extract_voice_text.py
输出:web/harness/voice_text.json {"game": {"id": "全文", ...}}
"""
import ast
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "tools"))
import gen_voice_dual as gvd # noqa: E402
out = {}
for game, lines in gvd.GAMES.items():
table = {}
for fid, _ins, text in lines:
if fid in table:
raise SystemExit(f"重复 id:{game}/{fid}")
table[fid] = text
# NPC 单音色平铺(gen_voice_dual.NPCS:id, speaker, instruct, 台词)
for fid, _sp, _ins, text in gvd.NPCS.get(game, []):
if fid in table:
raise SystemExit(f"重复 id:{game}/{fid}")
table[fid] = text
out[game] = table
def parse_legacy(py_path: Path) -> dict:
"""AST 解析旧版 gen_voice.py:提取 ('id', ("Speaker", "instruct"), "text") 元组。
不能 import——这些脚本顶层直接执行生成。"""
tree = ast.parse(py_path.read_text(encoding="utf-8"))
found = {}
for node in ast.walk(tree):
if not isinstance(node, ast.Tuple) or len(node.elts) != 3:
continue
a, _b, c = node.elts
if (isinstance(a, ast.Constant) and isinstance(a.value, str)
and isinstance(c, ast.Constant) and isinstance(c.value, str)
and len(c.value) >= 2):
found[a.value] = c.value
return found
# 旧 flavor 脚本补齐角色台词(storyline 林晚等、escape 角色音);主表优先,不覆盖
for game, legacy in [("storyline", ROOT / "app/src/storyline/gen/gen_voice.py"),
("escape", ROOT / "app/src/escape/gen/gen_voice.py")]:
for fid, text in parse_legacy(legacy).items():
out[game].setdefault(fid, text)
dest = ROOT / "web" / "harness" / "voice_text.json"
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8")
total = sum(len(v) for v in out.values())
print(f"OK {dest.relative_to(ROOT)} games={len(out)} lines={total}")