105 lines
5.7 KiB
Python
105 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify Mara's displayed story, directed Qwen readings and lossless masters."""
|
|
import array
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import wave
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
source, raw = root / 'assets/narration', root / 'assets/audio'
|
|
def read(path): return json.loads(path.read_text())
|
|
def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
canonical = read(source / 'scripts.json')
|
|
parts = re.split(r'^## (\S+) \| (.+)\n\n', (source / 'STORY.md').read_text(), flags=re.M)
|
|
manuscript = {parts[i]: parts[i+2].strip().replace('\n\n<!-- Narrator -->\n\n', '\n\n')
|
|
for i in range(1, len(parts), 3)}
|
|
assert manuscript == {r['pageId']: r['text'] for r in canonical}, 'Recompile the edited manuscript'
|
|
campaign = read(root / 'assets/campaign.json')['levels']
|
|
pages = {p['id']: p for p in read(root / 'assets/notebook.json')['pages']}
|
|
manifest = read(source / 'manifest.json')
|
|
runtime = read(raw / 'narration_manifest.json')
|
|
cast, performance = read(source / 'cast.json'), read(source / 'performance.json')
|
|
assert runtime['tracks'] == manifest['tracks']
|
|
assert manifest['engine'] == performance['engine'] == 'qwen3-voice-design'
|
|
assert manifest['model'] == performance['model']
|
|
assert manifest['modelRevision'] == performance['revision']
|
|
assert manifest['speakers'] == cast and manifest['performance'] == performance
|
|
assert manifest['sourceSha256'] == {name: sha(source / name)
|
|
for name in ('scripts.json', 'cast.json', 'performance.json')}
|
|
assert len(canonical) == len(manifest['tracks']) == 28
|
|
assert {r['pageId'] for r in canonical} == set(manifest['tracks'])
|
|
assert {p['id'] for p in pages.values() if p['type'] != 'puzzle'} == {
|
|
r['pageId'] for r in canonical if r['pageId'].startswith('cottage.')}
|
|
|
|
def joined(*parts): return '\n\n'.join(p for p in parts if p)
|
|
|
|
for record in canonical:
|
|
page_id = record['pageId']
|
|
if page_id.startswith('campaign.'):
|
|
_, index, phase = page_id.split('.')
|
|
level = campaign[int(index)]
|
|
expected = joined(level[phase], level.get(phase + 'Continuation', ''))
|
|
else:
|
|
page = pages[page_id]
|
|
source_kind = page.get('textSource')
|
|
if source_kind in ('before', 'after'):
|
|
level = campaign[page['campaignIndex']]
|
|
expected = joined(level[source_kind], page.get('continuation', level.get(source_kind + 'Continuation', '')))
|
|
elif source_kind == 'recording':
|
|
expected = joined(record.get('baseText', record['text']), page.get('continuation', ''))
|
|
else:
|
|
expected = joined(page['text'], page.get('continuation', ''))
|
|
assert page['speaker'] == record['speaker']
|
|
assert record['text'] == expected, f'Stale displayed text: {page_id}'
|
|
track = manifest['tracks'][page_id]
|
|
assert track['text'] == record['text']
|
|
assert track['textSha256'] == hashlib.sha256(record['text'].encode()).hexdigest()
|
|
assert track['resource'] == record['resource']
|
|
assert track['production'] == record['production'] == 'mara-qwen-v1'
|
|
assert track['engine'] == performance['engine']
|
|
assert track['model'] == performance['model'] and track['modelRevision'] == performance['revision']
|
|
assert track['segments'] == record['segments']
|
|
assert track['speaker'] == record['speaker']
|
|
assert track['asset'] == 'assets/audio/' + track['file']
|
|
assert track['asset'] in (root / 'pubspec.yaml').read_text()
|
|
if record.get('continuation'):
|
|
assert record['text'] == joined(record['baseText'], record['continuation'])
|
|
assert track['continuationSpeaker'] == 'Narrator'
|
|
assert track['cueJoin'] == ''
|
|
assert ''.join(c['text'] for c in track['cues']) == record['text']
|
|
assert len(track['cues']) == len(record['segments'])
|
|
previous = 0
|
|
for segment, cue in zip(record['segments'], track['cues']):
|
|
assert cue['text'] == segment['text']
|
|
assert cue['speaker'] == segment['speaker']
|
|
role = cast[segment['speaker']]
|
|
assert cue['voice'] == role['voice']
|
|
assert cue['instruct'] == ' '.join((role['designPrompt'], performance['delivery'], segment['direction']))
|
|
assert previous <= cue['startMs'] < cue['endMs'] <= track['durationMs']
|
|
previous = cue['endMs']
|
|
for event in track['events']:
|
|
assert 0 <= event['startMs'] < event['endMs'] <= track['durationMs']
|
|
assert all(event['endMs'] <= c['startMs'] or event['startMs'] >= c['endMs'] for c in track['cues'])
|
|
wav, flac = source / 'wav' / track['file'], raw / track['flacFile']
|
|
assert sha(raw / track['file']) == sha(wav) == track['wavSha256']
|
|
assert sha(flac) == track['flacSha256']
|
|
with wave.open(str(wav), 'rb') as reader:
|
|
assert (reader.getnchannels(), reader.getsampwidth(), reader.getframerate()) == (1, 2, 24000)
|
|
assert reader.getnframes() == track['frames']
|
|
pcm = reader.readframes(reader.getnframes())
|
|
assert track['sampleRate'] == 24000 and track['channels'] == 1
|
|
assert abs(track['durationMs'] - round(track['frames'] / 24)) <= 1
|
|
peak = max(abs(v) for v in array.array('h', pcm))
|
|
assert 1000 < peak < 32000, 'Silent or clipped audio'
|
|
decoded = subprocess.check_output(['ffmpeg', '-v', 'error', '-i', str(flac),
|
|
'-f', 's16le', '-acodec', 'pcm_s16le', '-'])
|
|
assert decoded == pcm, 'FLAC archive differs from PCM master'
|
|
print(f'PASS {page_id}: {track["durationMs"]/1000:.1f}s; text, direction, cues, PCM and FLAC match')
|
|
for path in (root / 'lib').rglob('*.dart'):
|
|
assert 'flutter_tts' not in path.read_text(), f'Device reader reintroduced in {path}'
|
|
minutes = sum(t['durationMs'] for t in manifest['tracks'].values()) / 60000
|
|
print(f'PASS all {len(canonical)} Qwen readings, {minutes:.1f} minutes; bundled playback only.')
|