From 91c04284965fdac77d74450f01ff26b6620e1b3e Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:32:49 +0100 Subject: [PATCH] Diagnose Anna Vogel plural phonemes and compare sentence prosody --- .../README.md | 11 + .../README.md | 116 ++++++++++ .../experiment.py | 150 ++++++++++++ .../pronunciation.py | 12 + .../results.json | 219 ++++++++++++++++++ .../score.py | 30 +++ .../transcriptions.json | 38 +++ .../tts-candidate-shortlist-2026-10-27.md | 12 +- 8 files changed, 583 insertions(+), 5 deletions(-) create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/README.md create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/experiment.py create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/pronunciation.py create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/results.json create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/score.py create mode 100644 docs/experiments/kikiri-anna-pronunciation-2026-10-27/transcriptions.json diff --git a/docs/experiments/kikiri-anna-full20-continuation-2026-10-27/README.md b/docs/experiments/kikiri-anna-full20-continuation-2026-10-27/README.md index e20757b..bf4571e 100644 --- a/docs/experiments/kikiri-anna-full20-continuation-2026-10-27/README.md +++ b/docs/experiments/kikiri-anna-full20-continuation-2026-10-27/README.md @@ -144,3 +144,14 @@ Private original audio/transcripts, model weights, endpoint snapshots, keys and the local UI screenshot stay out of Git. All original material and previous selected checkpoints are retained. This is a bounded comparison; more epochs are not automatically warranted without a useful listening improvement. + +## Subsequent listening decision + +Michael selected **`anna-full20-plus20-expressive.wav`**: it is now almost the +original Anna voice to his ears. He still hears **Vögel as Wögel**, independently +confirming the earlier ASR discrepancy as an audible problem, and a slight +robotic character. This supersedes the pending listening status above; it does +not approve an endpoint switch. Keep this exact +20 model/voicepack as the new +reference. The separate [pronunciation/prosody experiment](../kikiri-anna-pronunciation-2026-10-27/README.md) +investigates those two residual issues without changing this checkpoint or +training more epochs automatically. diff --git a/docs/experiments/kikiri-anna-pronunciation-2026-10-27/README.md b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/README.md new file mode 100644 index 0000000..3fc5e7d --- /dev/null +++ b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/README.md @@ -0,0 +1,116 @@ +# Anna +20: Vögel pronunciation and separate prosody test · 27 October 2026 + +Michael hears `anna-full20-plus20-expressive.wav` as almost the original Anna, +with two residual issues: **Vögel → Wögel** and a slight robotic character. +Preserve that exact model and voicepack; do not activate a new TTS endpoint, +train more, edit clients or unload Qwen for this bounded CPU experiment. + +## Diagnosis and controlled comparison + +The actual installed German DEG2P/espeak pipeline outputs `vˈøːɡəl` for +**Vögel**: IPA /v/ is the voiced sound of German W here. **Vogel** already +receives `fˈoːɡəl`. Vögeln/Vögelchen show the same plural-stem issue. These +words have no existing package override. This is a concrete frontend error +before neural synthesis, not a diagnosis based solely on STT. + +`pronunciation.py` is an **experiment-only** exact correction of that stem +to /f/. It requires a corresponding Vögel/Vögeln/Vögelchen word in the text, +handles NFC/NFD text, and leaves all other phonemes unchanged. It never replaces +all V/W letters or /v/ phonemes. Controls include Vogel, Vogelhaus, Vogelstimmen, +wieder, Wörter, Vase, Ventil, Video, Vulkan, vier, viel, Vater and literal Wögel. +This does not modify the installed package, the central Athena text enhancer, +training labels, checkpoint, repository input text or production worker. + +Four synthetic WAVs use the same +20 model/voicepack and four CPU threads: + +1. Exact expressive baseline, required to match the selected WAV SHA-256. +2. Same full expressive paragraph, changing only the erroneous /v/ to /f/. +3. The corrected expressive text synthesized as six separate sentences with + 120 ms of additional silence between them. This tests shorter prosody context, + not a proven remedy for robotic timbre. No pitch shift, denoising, resampling, + time stretch or new voice embedding is applied. +4. Corrected story paragraph, to check the word in a second context. + +Only the fixed synthetic passages use this trivial sentence split; it is not +a robust production splitter for abbreviations, dates or arbitrary German. +The sentence arm changes context and adds pauses, so any listening difference +cannot be attributed to the pronunciation correction alone. Do not claim +robotic character is reduced from STT, file metrics or loss values. + +## Native runtime and retained data + +Explicit read-only dependencies, versions, pinned code and private-data lineage +are in the [selected checkpoint experiment](../kikiri-anna-full20-continuation-2026-10-27/README.md) +and its linked original setup. Reuse the existing standalone Python 3.11.18 +CPU-only Torch 2.6.0 environment, pinned Kokoro/Misaki/Kikiri sources, espeak +loader and model files. Install nothing and create no persistent service. +Own private root: `/data/athena-kikiri-anna-pronunciation-20261027`, mode 0700. + +Run `experiment.py` with +`/data/athena-kikiri-victoria-cpu-20261027/venv/bin/python` in a transient +systemd unit: quota 400%, allowed CPUs 2–5/8–11, nice 10, memory 3 GiB/no swap, +private network/devices, read-only system, own root writable, limit 180 s. +GPU visibility is disabled and CPU-only Torch is asserted. No model requests +or production profile changes are made. `score.py` runs local Parakeet with +two threads in another limited CPU unit. Capture relevant before/after hashes +and worker PIDs, and independently rehash the selected model/voicepack. + +A fresh native host must reproduce the explicit parent environment and restore +the private selected model/voicepack; these experiments are not a native +installer or a complete encrypted restore test. No new backup is created. +Only scripts, synthetic metrics and listening verdicts enter Git; private Anna +recordings/transcripts, weights, operator keys and production snapshots do not. + +## Sources checked + +- [Pinned German G2P](https://github.com/semidark/misaki/blob/6d252a2e02f3b030f22f56686f1a73786c16ffc8/misaki/de.py). +- [German pipeline upstream proposal](https://github.com/hexgrad/kokoro/pull/317). +- [Kikiri source and documented troubleshooting](https://github.com/semidark/kikiri-tts). +- The installed source and its actual phoneme output, rather than an assumed + dictionary pronunciation or a claim of an official vendor fix. + +## Results + +All four renders completed successfully. The baseline reproduced the selected +`anna-full20-plus20-expressive.wav` byte for byte. Eighteen actual G2P controls +passed; the full-paragraph fixed arm changes exactly one /v/ to /f/ and no +other phoneme. Original model/voicepack SHA-256 remained unchanged. + +| Arm | Audio | CPU generation | RTF | ASR word edits | +| --- | --- | --- | --- | --- | +| Selected +20 baseline | 15.550 s | 5.164 s | 0.3321 | 1: Wögel | +| Vögel fixed, whole paragraph | 15.525 s | 5.315 s | 0.3423 | 0 | +| Vögel fixed, six sentences | 18.800 s | 4.734 s | 0.2518 | 0 | +| Vögel fixed, second story | 15.550 s | 4.722 s | 0.3037 | 0 | + +Parakeet recognized **Vögel** correctly in all three corrected outputs; all +remaining normalized words matched. Punctuation differences are not scored. +This provides evidence for the targeted pronunciation correction. It does +not certify naturalness, Anna identity or removal of the robotic character. +That separate listening comparison is pending. The six-sentence output includes +five explicit 120-ms gaps (0.600 s total); its longer duration also reflects +the model's different sentence-boundary timing. Do not count the added silence +as speech throughput or claim a general speedup from these single renders. + +Every file is mono 24-kHz PCM16, finite, with zero clipped samples and zero +dropped phonemes. Copied local WAVs match their recorded hashes and durations. +Model load is reported separately; the timing table excludes load and includes +the actual generation path after warmup. No pitch correction or sound filter +was used. The original preferred +20 file remains available unchanged. + +Relevant production configuration hashes, CPU TTS PIDs, Deck start time and +**the same running Strata PID** were unchanged across the complete experiment. +No production model request, unload, reload or service restart occurred. +Both transient test units exited successfully and no permanent process remains. + +Michael subsequently reiterated the operational constraint explicitly: +**Strata/Qwen must remain loaded now.** Do not use any earlier GPU-training +permission to unload it. This comparison was already CPU-only and had preserved +Qwen. Further work under this constraint must not free its GPUs or interrupt +its requests. Active TTS remains unchanged; no production correction is installed. + +Local listening files: +`/Users/mike_i386/Documents/ChatGPT/Athena Deck/work/kikiri-anna-pronunciation-20261027/audio/anna-plus20-voegel-fixed.wav` +and `anna-plus20-sentences-fixed.wav`. Baseline and corrected-story files are +retained in the same directory. Scripts/results are versioned; WAVs stay outside +Git. No native/client playback integration or fresh-host restore is certified. diff --git a/docs/experiments/kikiri-anna-pronunciation-2026-10-27/experiment.py b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/experiment.py new file mode 100644 index 0000000..41745d6 --- /dev/null +++ b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/experiment.py @@ -0,0 +1,150 @@ +"""CPU-only pronunciation correction and a separate sentence-prosody comparison.""" +from pathlib import Path +import os, sys, json, time, hashlib, random, re + +ROOT = Path('/data/athena-kikiri-anna-pronunciation-20261027') +PARENT = Path('/data/athena-kikiri-anna-full20-next-20261027') +PUBLIC = Path('/data/athena-kikiri-victoria-cpu-20261027') +os.umask(0o077) +ROOT.mkdir(exist_ok=True, mode=0o700) +(ROOT/'tmp').mkdir(exist_ok=True, mode=0o700) +os.environ.update(CUDA_VISIBLE_DEVICES='', HF_HUB_OFFLINE='1', + HF_HUB_DISABLE_TELEMETRY='1', HF_HUB_DISABLE_IMPLICIT_TOKEN='1', + HF_HOME=str(ROOT/'cache/huggingface'), TMPDIR=str(ROOT/'tmp'), + XDG_CACHE_HOME=str(ROOT/'cache'), OMP_NUM_THREADS='4', + OPENBLAS_NUM_THREADS='1', TOKENIZERS_PARALLELISM='false') + +import numpy as np +import soundfile as sf +import torch, torch._dynamo +from kokoro import KModel, KPipeline +from pronunciation import correct +sys.path.append(str(PARENT)) +from support import snapshot + + +def write(name, value): + (ROOT/name).write_text(json.dumps(value, indent=2, ensure_ascii=False)) + + +def sha(path): + with path.open('rb') as f: + return hashlib.file_digest(f, 'sha256').hexdigest() + + +assert torch.version.cuda is None and not torch.cuda.is_available() +torch.set_num_threads(4) +torch.set_num_interop_threads(1) +os.sched_setaffinity(0, {2,3,4,5,8,9,10,11}) +before = snapshot() +write('production-before.json', before) +model_path = PARENT/'models/extra-20/model.pth' +voice_path = model_path.parent/'voice.pt' +initial_hashes = [sha(model_path), sha(voice_path)] +selected = json.loads((PARENT/'cpu-plus20.json').read_text()) +assert initial_hashes == [selected['model_sha256'], selected['voice_sha256']] +report = dict(model_sha256=initial_hashes[0], voice_sha256=initial_hashes[1], + device='cpu', threads=4, seed=42, sample_rate=24000, complete=False, runs=[]) +started = time.monotonic() +random.seed(42); np.random.seed(42); torch.manual_seed(42) +model = KModel(repo_id='hexgrad/Kokoro-82M', config=str(PUBLIC/'source/training/config.json'), + model=str(model_path)).to('cpu').eval() +weights = torch.load(model_path, map_location='cpu', weights_only=True) +for name, state in weights.items(): + component = getattr(model, name) + state = {k.removeprefix('module.'): v for k,v in state.items()} + result = component.load_state_dict(state, strict=False) + assert not result.unexpected_keys + current = component.state_dict() + for key in result.missing_keys: + path, param = key.rsplit('.',1) + layer = component.get_submodule(path) + assert isinstance(layer, torch.nn.InstanceNorm1d) and layer.affine + assert param in ('weight','bias') + assert torch.all(current[key] == (1 if param == 'weight' else 0)) + state[key] = current[key] + component.load_state_dict(state, strict=True) +del weights +voice = torch.load(voice_path, map_location='cpu', weights_only=True) +assert voice.shape == (510,1,256) and torch.isfinite(voice).all() +pipeline = KPipeline(lang_code='d', repo_id='hexgrad/Kokoro-82M', model=model, device='cpu') +g2p = pipeline.g2p +report['model_load_seconds'] = time.monotonic()-started +report['parameters'] = sum(p.numel() for p in model.parameters()) + +checks = [] +for text in ('Vogel','Vögel','Vögeln','Vögelchen','Vogelhaus','Vogelstimmen', + 'wieder','Wörter','Vase','Ventil','Video','Vulkan','vier','viel','Vater', + 'Wögel','Vögel singen.','Die Vögel suchen Schutz.'): + original = g2p(text)[0].replace('ʏ','y') + fixed = correct(text, original) + expected_change = text in ('Vögel','Vögeln','Vögelchen','Vögel singen.','Die Vögel suchen Schutz.') + assert (fixed != original) == expected_change, text + if expected_change: + assert fixed == original.replace('vˈøːɡəl','fˈøːɡəl') + checks.append(dict(text=text, before=original, after=fixed, changed=fixed!=original)) +report['phoneme_controls'] = checks + + +def render(text, arm, fixed=False, sentences=False, save=True): + def front(s): + ps, tokens = g2p(s) + ps = ps.replace('ʏ','y') + return (correct(s, ps) if fixed else ps), tokens + pipeline.g2p = front + # Sentence list is a test of shorter model context, not an automatic + # production splitter. It is safe only for these fixed synthetic passages. + pieces = re.split(r'(?<=[.!?])\s+',text) if sentences else [text] + random.seed(42); np.random.seed(42); torch.manual_seed(42) + started = time.monotonic() + chunks=[]; phones=[]; gaps=0 + for r in pipeline(pieces, voice=voice, speed=1): + assert len(r.phonemes)<=510 + x = r.audio.detach().cpu().numpy().reshape(-1) + assert np.isfinite(x).all() + if sentences and chunks: + chunks.append(np.zeros(2880,dtype=np.float32)); gaps+=1 + chunks.append(x); phones.append(r.phonemes) + elapsed = time.monotonic()-started + x = np.concatenate(chunks) + duration = len(x)/24000 + dropped = sorted({c for ps in phones for c in ps if c not in model.vocab}) + assert not dropped and not np.any(np.abs(x)>=1) + row = dict(arm=arm,text=text,phonemes=phones,segments=len(phones), + gap_seconds=gaps*.12, duration_seconds=duration,generation_seconds=elapsed, + rtf=elapsed/duration,realtime_multiple=duration/elapsed, + clipped_fraction=float(np.mean(np.abs(x)>=1)),dropped=dropped) + if save: + path=ROOT/'outputs'/f'anna-plus20-{arm}.wav' + sf.write(path,x,24000,subtype='PCM_16') + row.update(file=path.name,sha256=sha(path)) + return row + + +(ROOT/'outputs').mkdir(exist_ok=True,mode=0o700) +report['warmup'] = render('Die Stimme ist bereit.','warmup',save=False) +expressive = next(r for r in selected['runs'] if r['case']=='expressive') +story = next(r for r in selected['runs'] if r['case']=='story') +try: + base = render(expressive['text'],'baseline') + assert base['sha256']==expressive['sha256'],'Selected +20 baseline must reproduce exactly' + base['matches_selected_parent']=True + report['runs'].append(base) + fixed = render(expressive['text'],'voegel-fixed',fixed=True) + assert fixed['phonemes'] == [p.replace('vˈøːɡəl','fˈøːɡəl') for p in base['phonemes']] + report['runs'].append(fixed) + report['runs'].append(render(expressive['text'],'sentences-fixed',fixed=True,sentences=True)) + report['runs'].append(render(story['text'],'story-fixed',fixed=True)) + report['complete']=True +finally: + after = snapshot() + report['preservation'] = dict(files_equal=before['hashes']==after['hashes'], + cpu_tts_pids_equal=before['pids']['articulino']==after['pids']['articulino'] and before['pids']['qwen_tts']==after['pids']['qwen_tts'], + deck_start_equal=before['deck_started']==after['deck_started'], + strata_pids_equal=before['pids']['strata']==after['pids']['strata'], + selected_exports_unchanged=initial_hashes==[sha(model_path),sha(voice_path)]) + write('production-after.json',after) + write('results.json',report) + print(json.dumps(dict(complete=report['complete'],preservation=report['preservation'], + runs=[{k:r[k] for k in ('arm','duration_seconds','generation_seconds','rtf')} for r in report['runs']])),flush=True) +assert all(report['preservation'].values()) diff --git a/docs/experiments/kikiri-anna-pronunciation-2026-10-27/pronunciation.py b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/pronunciation.py new file mode 100644 index 0000000..6127046 --- /dev/null +++ b/docs/experiments/kikiri-anna-pronunciation-2026-10-27/pronunciation.py @@ -0,0 +1,12 @@ +"""Experimental exact Vögel-form correction; never a general v -> f rule.""" +import re +import unicodedata + +WORD = re.compile(r'\bvögel(?:n|chen)?\b', re.IGNORECASE) +PHONE = re.compile(r'(?