Complete cottage notebook with narration and discovery-only artwork

This commit is contained in:
Hadrian Burkhardt
2026-11-01 00:18:34 +01:00
parent 36fbbce6ef
commit 6bd14a9e20
90 changed files with 2394 additions and 221 deletions
+16 -2
View File
@@ -5,14 +5,28 @@ from pathlib import Path
root=Path(__file__).resolve().parents[1]
source=root/'assets/narration';raw=root/'assets/audio'
canonical=json.loads((source/'scripts.json').read_text())
campaign=json.loads((root/'assets/campaign.json').read_text())['levels']
pages={p['id']:p for p in json.loads((root/'assets/notebook.json').read_text())['pages']}
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'])
assert len(canonical)==len(manifest['tracks'])
assert {r['pageId'] for r in canonical}==set(manifest['tracks'])
for record in canonical:
if record['pageId'].startswith('campaign.'):
_,index,phase=record['pageId'].split('.')
assert record['text']==campaign[int(index)][phase], 'Campaign narration is stale'
elif record.get('speaker')=='Narrator':
page=pages[record['pageId']]
expected=campaign[page['campaignIndex']][page['textSource']] if page.get('textSource') in ('before','after') else page['text']
assert record['text']==expected, 'Notebook narration is stale'
track=manifest['tracks'][record['pageId']]
assert track['text']==record['text']
assert track['textSha256']==hashlib.sha256(record['text'].encode()).hexdigest()
assert track['resource']==record['resource']
if record.get('speaker')=='Narrator':
assert track['speaker']=='Narrator' and track['voice']=='bm_george'
assert track['speed']==record['speed']
assert 'assets/audio/'+track['file'] in (root/'pubspec.yaml').read_text()
assert '\n\n'.join(cue['text'] for cue in track['cues'])==record['text']
previous=0
for cue in track['cues']:
@@ -33,4 +47,4 @@ for record in canonical:
print(f"PASS {record['pageId']}: {track['durationMs']/1000:.1f}s, WAV/master match, FLAC lossless, text/cues match")
for p in (root/'lib').rglob('*.dart'):
assert 'flutter_tts' not in p.read_text(),f'Device reader reintroduced in {p}'
print('All five recordings verified; bundled file playback only.')
print(f'All {len(canonical)} recordings verified; bundled file playback only.')
+8 -4
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Prepare immutable WAV masters and bundled FLACs; Android performs no speech synthesis."""
"""Prepare WAV masters, runtime WAVs and archival FLACs; playback never synthesizes speech."""
import argparse, hashlib, importlib.metadata, json, subprocess, shutil
from pathlib import Path
import numpy as np
@@ -14,6 +14,7 @@ parser.add_argument('--model',type=Path,required=True)
parser.add_argument('--voices',type=Path,required=True)
parser.add_argument('--voice',default='bf_emma')
parser.add_argument('--speed',type=float,default=.82)
parser.add_argument('--speaker', help='Render only this speaker, preserving all other recordings')
parser.add_argument('--root',type=Path,default=Path(__file__).resolve().parents[1])
a=parser.parse_args()
source=a.root/'assets/narration';raw=a.root/'assets/audio'
@@ -23,8 +24,10 @@ session=ort.InferenceSession(str(a.model),sess_options=options,providers=['CPUEx
session.disable_fallback()
config=EspeakConfig(lib_path=str(espeakng_loader.get_library_path()),data_path=str(espeakng_loader.get_data_path()))
engine=Kokoro.from_session(session,str(a.voices),espeak_config=config)
tracks={}
previous=json.loads((source/'manifest.json').read_text()) if (source/'manifest.json').exists() else {}
tracks=dict(previous.get('tracks',{})) if a.speaker else {}
for record in json.loads((source/'scripts.json').read_text()):
if a.speaker and record.get('speaker')!=a.speaker: continue
paragraphs=[]
for part in record['text'].split('\n\n'):
if paragraphs and len(part)<45:paragraphs[-1]+='\n\n'+part
@@ -33,7 +36,7 @@ for record in json.loads((source/'scripts.json').read_text()):
rate=24000;pieces=[np.zeros(int(rate*.18),dtype=np.float32)];frames=len(pieces[0]);cues=[]
for part in paragraphs:
print(f"Rendering {record['pageId']} · {len(cues)+1}/{len(paragraphs)}",flush=True)
samples,sample_rate=engine.create(part.replace('\n',' '),voice=a.voice,speed=a.speed,lang='en-gb',sentence_pause=.38,clause_pause=.14)
samples,sample_rate=engine.create(part.replace('\n',' '),voice=record.get('voice',a.voice),speed=record.get('speed',a.speed),lang='en-gb',sentence_pause=.38,clause_pause=.14)
assert sample_rate==rate
samples=np.asarray(samples,dtype=np.float32).reshape(-1)
assert len(samples)>rate*.3 and np.isfinite(samples).all()
@@ -55,8 +58,9 @@ for record in json.loads((source/'scripts.json').read_text()):
'flacSha256':hashlib.sha256(flac.read_bytes()).hexdigest(),'cues':cues}
print(f"Saved {wav.name}: {len(audio)/rate:.1f}s; lossless FLAC verified",flush=True)
manifest={'voice':a.voice,'speed':a.speed,'language':'en-gb','method':'Synthetic narration rendered during development; bundled file playback only.',
'speakers':{'Mara':{'voice':'bf_emma','speed':.82},'Narrator':{'voice':'bm_george','speed':.88}},
'modelSha256':hashlib.sha256(a.model.read_bytes()).hexdigest(),'voicesSha256':hashlib.sha256(a.voices.read_bytes()).hexdigest(),
'packages':{p:importlib.metadata.version(p) for p in ['kokoro-onnx','onnxruntime','soundfile','espeakng-loader']},'tracks':tracks}
(source/'manifest.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n')
(raw/'narration_manifest.json').write_text(json.dumps({'tracks':tracks},ensure_ascii=False,indent=2)+'\n')
print('All five narration masters and runtime FLACs prepared.',flush=True)
print(f'{len(tracks)} narration masters and runtime assets prepared.',flush=True)