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
+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)