Files
breeze/tests/practice_narration_keys_test.py
T
waozi 939593a1e6 Checkpoint media compression, narration, and app updates
Preserve current AVIF compression, local voice pipelines, practice workflows, UI API migration, locale updates, and packaging work. Native integration validation remains pending.
2026-11-10 22:20:31 -03:00

58 lines
3.3 KiB
Python

"""Every spoken cue in the shipped course has narration, without Node tooling."""
import json
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
from practice_content import course_narration_keys
from practice_media import media_path
config = json.loads((ROOT / 'design/tai-chi/narration.json').read_text())
actual = json.loads((ROOT / config['keys_file']).read_text())
course = media_path('assets/practices/taichi/course.tch').read_bytes()
expected = course_narration_keys(course)
assert len(expected) > 200
assert actual == expected, 'Export Tai Chi after changing spoken cues'
for broken in (b'TCH3' + course[4:], course[:-1], b'TCH2\xff\xff\xff\xff'):
try:
course_narration_keys(broken)
except ValueError:
continue
raise AssertionError('Malformed course accepted')
print(f'All {len(expected)} shipped course narration lines are covered; unspoken labels are excluded')
# Sun Salutation speaks one line per breath, each recorded in every voice.
import importlib.util
import re
labels = (ROOT / 'src/practices/sun_salutation/sun_salutation_labels.zi').read_text()
spoken = set(re.findall(r'"(sun_salutation_voice_[a-z0-9_]+)"', labels))
content = json.loads((ROOT / 'apps/practice/content.json').read_text())
rules = (ROOT / 'src/practices/sun_salutation/sun_salutation_rules.zi').read_text()
breath = int(re.search(r'SUN_SALUTATION_DEFAULT_END_SECONDS :: (\d+)', rules)[1])
speech_spec = importlib.util.spec_from_file_location('narration', ROOT / 'scripts/generate-lumi-guide-narration.py')
narration = importlib.util.module_from_spec(speech_spec)
speech_spec.loader.exec_module(narration)
entries = narration.entries
codes = narration.locale_codes()
assert set(codes) == {'en', 'es', 'cs', 'de', 'fr', 'ru', 'ja', 'ko', 'zh', 'pt'}
for name in ('sunsalutation', 'sunsalutation_male'):
speech = json.loads((ROOT / content['narration'][name]['config']).read_text())
lines = json.loads((ROOT / speech['keys_file']).read_text())
assert set(lines) == spoken, f'{name}: narration lines differ from the spoken keys'
# Each line is written in every language, recorded from that text, and
# fits the shortest default breath with the player's 0.2 s margin.
receipt = json.loads((ROOT / content['narration'][name]['receipt']).read_text())['clips']
narration.VOICE = media_path(content['narration'][name]['output_directory'])
for code in codes:
narration.LOCALES = media_path(content['narration'][name]['text_directory'])
texts = {key: text for _, key, text in narration.wanted(speech, [code], spoken)}
for key in spoken:
text = texts.get(key, '').strip()
assert text, f'{code}/{key}: no {name} narration text'
clip = receipt.get(f'{code}/{key}')
assert narration.current({'clips': receipt}, speech, code, key, text), f'{code}/{key}: {name} recording is missing, unverified or older than its text'
assert media_path(clip['file']).is_file(), f'{code}/{key}: {name} clip file is missing'
assert clip['seconds'] + 0.2 <= breath, f'{code}/{key}: {name} line is {clip["seconds"]} s, longer than a {breath} s breath'
print(f'All {len(spoken)} Sun Salutation lines are recorded in {len(codes)} languages and both voices, each within a {breath} s breath')