#!/usr/bin/env python3 """Verify every bundled recording matches the current diary text and its WAV master.""" import array, hashlib, json, math, subprocess, tempfile, wave from pathlib import Path root=Path(__file__).resolve().parents[1] source=root/'assets/narration';raw=root/'app/src/main/res/raw' with tempfile.TemporaryDirectory(prefix='lumen-audio-text-') as temp: subprocess.run(['javac','-d',temp,str(root/'app/src/main/java/com/lumen/daily/StoryBook.java'),str(root/'scripts/ExportNarration.java')],check=True) canonical=json.loads(subprocess.check_output(['java','-cp',temp,'com.lumen.daily.ExportNarration'])) assert canonical==json.loads((source/'scripts.json').read_text()),'Regenerate the script export after editing diary text' manifest=json.loads((source/'manifest.json').read_text());runtime=json.loads((raw/'narration_manifest.json').read_text()) assert runtime['tracks']==manifest['tracks'] assert len(canonical)==5==len(manifest['tracks']) for record in canonical: track=manifest['tracks'][record['pageId']] assert track['text']==record['text'] assert track['textSha256']==hashlib.sha256(record['text'].encode()).hexdigest() assert track['resource']==record['resource'] assert '\n\n'.join(cue['text'] for cue in track['cues'])==record['text'] previous=0 for cue in track['cues']: assert previous<=cue['startMs']