Old Tam says "W, A, S and D", not "Wasad" (Gitea #3, first part); make_voice.py re-records a line when how it's spoken changes, not only its text

This commit is contained in:
Paul Bailey
2026-11-08 20:32:09 +00:00
parent 8f3c58c810
commit 4a691b72e1
3 changed files with 64 additions and 1 deletions

View File

@@ -45,17 +45,35 @@ def spoken(text):
s = s.replace(" · ", ", ").replace("&", "and")
s = re.sub(r"\bLMB\b", "left click", s)
s = re.sub(r"\bRMB\b", "right click", s)
s = re.sub(r"\bWASD\b", "W, A, S and D", s) # (Gitea #3: it said "Wasad")
s = re.sub(r"\s+,", ",", s)
return s
def _changed_by_new_rules(text):
"""Whether a line has something the spoken() rules added since the last
full recording (0.6.2): "WASD"."""
return re.search(r"\bWASD\b", text) is not None
def main():
redo_all = "--all" in sys.argv
os.makedirs(OUT, exist_ok=True)
manifest_path = os.path.join(OUT, "lines.json")
old = json.load(open(manifest_path)) if os.path.exists(manifest_path) else {}
# What each recording SAYS (spoken() of its text), so a change to how a
# line is spoken re-records it too. (lines.json keeps the written text's
# key: that's what the game checks against the screen.)
said_path = os.path.join(OUT, "spoken.json")
said = json.load(open(said_path)) if os.path.exists(said_path) else {}
todo = [(i, t) for i, t in lines()
if redo_all or old.get(i) != key(t) or not os.path.exists(os.path.join(OUT, i + ".ogg"))]
if redo_all or old.get(i) != key(t) or said.get(i, key(spoken(t))) != key(spoken(t))
or not os.path.exists(os.path.join(OUT, i + ".ogg"))]
if not said:
# (First run with spoken.json: lines spoken differently now than when
# they were recorded can't be told apart, so re-record the ones whose
# spoken form isn't just their text.)
todo += [(i, t) for i, t in lines() if spoken(t) != t and (i, t) not in todo and _changed_by_new_rules(t)]
keep = {i for i, _ in lines()}
for f in os.listdir(OUT): # lines that no longer exist
if f.endswith(".ogg") and f[:-4] not in keep:
@@ -78,6 +96,7 @@ def main():
print(" %s (%.1f s)" % (i, len(audio) / 24000 / 0.92 / 1.04))
manifest = {i: key(t) for i, t in lines()}
json.dump(manifest, open(manifest_path, "w"), indent="\t", sort_keys=True)
json.dump({i: key(spoken(t)) for i, t in lines()}, open(said_path, "w"), indent="\t", sort_keys=True)
print("%d lines, %d made now -> %s" % (len(manifest), len(todo), os.path.relpath(OUT, ROOT)))