Skip to content

fix(tts/pockettts): per-language mimi encoders for non-English voice cloning (#793) - #871

Merged
Alex-Wengg merged 2 commits into
mainfrom
fix/793-per-language-clone-encoder
Aug 19, 2026
Merged

fix(tts/pockettts): per-language mimi encoders for non-English voice cloning (#793)#871
Alex-Wengg merged 2 commits into
mainfrom
fix/793-per-language-clone-encoder

Conversation

@Alex-Wengg

Copy link
Copy Markdown
Member

Summary

Fixes the residual flaky/garbled non-English voice cloning reported in #793 (still present after #797).

Root cause

Every pocket-tts language pack ships its own mimi codec weights — all 87 mimi state-dict keys differ across languages, including all 43 encoder-side keys. The shared root mimi_encoderv2.mlmodelc was traced from the English model, so live-clone conditioning for non-English packs was built from the wrong codec's latents. The #797 reprojection corrected the projection, not the latents:

  • Swift conditioning vs the reference _encode_audio output: ~140% relative error (mean|diff| 0.149 vs signal 0.107), uniform across frames.
  • Injecting the Swift conditioning into the PyTorch reference generation reproduced the exact failure signature ("Maximum generation length reached without EOS" → long noise at low temperature, wrong-voice timbre), while PyTorch-native conditioning was 16/16 clean with the reporter's 5 s reference clip.
  • The deployed reprojection assets and the encoder trace itself were verified bit-exact/fp16-exact — the false premise was "mimi is shared across languages" (that July check compared versions of one language, not languages).

Fix

Prefer a pack-local per-language encoder v2.1/<lang>/mimi_encoderv3.mlmodelc (that pack's mimi + speaker_proj baked in; published for all 9 non-English packs on FluidInference/pocket-tts-coreml), fetched lazily on first clone. Its output is already in the pack's own conditioning space → no host-side reprojection. The shared root encoder + #797 reprojection remains the fallback (English, stale caches, offline).

  • PocketTtsResourceDownloader.ensurePackMimiEncoder — lazy, best-effort fetch; pack downloads for synthesis-only users stay lean (filter test added).
  • PocketTtsModelStore — pack-local-first encoder load; cloneProjection() skips reprojection for the pack-local encoder; 6L warning now scoped to the fallback path.
  • CLI: --temperature flag on the PocketTTS path (used to reproduce the reporter's matrix).

Validation (reporter's exact 5.15 s English reference, spanish_24l, 8 seeds × temp {0.15, 0.7})

pipeline intelligible noise runaways
PyTorch reference (native cloning) 16/16 0
FluidAudio before (shared encoder + reprojection) 7/16 4 (all at temp 0.15)
FluidAudio after (pack-local encoder) 15/16 0

Conditioning error vs PyTorch native: 140% → 0.06% relative. 6-layer spanish cloning goes from always-garbled to 3/4 intelligible (upstream-level — the earlier "6L broken upstream" verdict was an artifact of injecting English-mimi latents). german_24l verified through the real HF lazy-download path end-to-end.

Conversion script: mobius convert_mimi_encoder_lang.py (companion PR).

Fixes #793

🤖 Generated with Claude Code

…cloning (#793)

Root cause of the residual flaky/garbled non-English cloning: every
pocket-tts language pack ships its OWN mimi codec weights (all 87 mimi
state-dict keys differ across languages, including the 43 encoder-side
keys). The shared root mimi_encoderv2 was traced from the English model,
so live-clone conditioning for non-English packs was built from the wrong
codec's latents. The #797 reprojection corrected the projection but not
the latents — Swift conditioning differed from the reference _encode_audio
output by ~140% relative, and injecting it into the PyTorch reference
reproduced the exact failure signature (no-EOS runaway noise at low
temperature, wrong-voice timbre), while native conditioning was 16/16
clean with the same 5s reference clip.

Fix: prefer a pack-local per-language encoder
(v2.1/<lang>/mimi_encoderv3.mlmodelc, that pack's mimi + speaker_proj
baked in, published on FluidInference/pocket-tts-coreml) fetched lazily on
first clone. Its output is already in the pack's own conditioning space,
so no host-side reprojection is applied. The shared root encoder +
reprojection remains the fallback (English, stale caches, offline).

Swift e2e with the issue #793 reporter's reference on spanish_24l goes
from 7/16 intelligible (4 pure-noise runaways at temperature 0.15) to
15/16 — on par with the PyTorch reference under the same seeds. 6-layer
spanish cloning goes from always-garbled to 3/4 (upstream-level), so the
6L warn-and-steer now only fires on the fallback path.

Also adds a --temperature flag to the tts CLI (PocketTTS path) to make
reliability matrices reproducible.
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Supertonic3 Smoke Test ✅

Check Result
Build
Model download (incl. VectorEstimatorVariants/ int4 buckets)
Model load
Synthesis pipeline (--ve-variant int4)
Output WAV ✅ (364.7 KB)

Runtime: 0m30s

Note: CI VMs lack a physical Neural Engine; the ANE-bucketed VectorEstimator falls back to CPU here. This validates download + variant resolution + synthesis, not ANE residency/perf.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Parakeet EOU Benchmark Results ✅

Status: Benchmark passed
Chunk Size: 320ms
Files Tested: 100/100

Performance Metrics

Metric Value Description
WER (Avg) 7.03% Average Word Error Rate
WER (Med) 4.17% Median Word Error Rate
RTFx 10.29x Real-time factor (higher = faster)
Total Audio 470.6s Total audio duration processed
Total Time 47.4s Total processing time

Streaming Metrics

Metric Value Description
Avg Chunk Time 0.047s Average chunk processing time
Max Chunk Time 0.095s Maximum chunk processing time
EOU Detections 0 Total End-of-Utterance detections

Test runtime: 0m55s • 08/19/2026, 03:13 PM EST

RTFx = Real-Time Factor (higher is better) • Processing includes: Model inference, audio preprocessing, state management, and file I/O

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Offline VBx Pipeline Results

Speaker Diarization Performance (VBx Batch Mode)

Optimal clustering with Hungarian algorithm for maximum accuracy

Metric Value Target Status Description
DER 10.4% <20% Diarization Error Rate (lower is better)
RTFx 9.84x >1.0x Real-Time Factor (higher is faster)

Offline VBx Pipeline Timing Breakdown

Time spent in each stage of batch diarization

Stage Time (s) % Description
Model Download 21.705 20.4 Fetching diarization models
Model Compile 9.302 8.7 CoreML compilation
Audio Load 0.105 0.1 Loading audio file
Segmentation 28.427 26.7 VAD + speech detection
Embedding 106.363 99.7 Speaker embedding extraction
Clustering (VBx) 0.119 0.1 Hungarian algorithm + VBx clustering
Total 106.653 100 Full VBx pipeline

Speaker Diarization Research Comparison

Offline VBx achieves competitive accuracy with batch processing

Method DER Mode Description
FluidAudio (Offline) 10.4% VBx Batch On-device CoreML with optimal clustering
FluidAudio (Streaming) 17.7% Chunk-based First-occurrence speaker mapping
Research baseline 18-30% Various Standard dataset performance

Pipeline Details:

  • Mode: Offline VBx with Hungarian algorithm for optimal speaker-to-cluster assignment
  • Segmentation: VAD-based voice activity detection
  • Embeddings: WeSpeaker-compatible speaker embeddings
  • Clustering: PowerSet with VBx refinement
  • Accuracy: Higher than streaming due to optimal post-hoc mapping

🎯 Offline VBx Test • AMI Corpus ES2004a • 1049.0s meeting audio • 134.9s processing • Test runtime: 2m 22s • 08/19/2026, 03:16 PM EST

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Sortformer High-Latency Benchmark Results

ES2004a Performance (30.4s latency config)

Metric Value Target Status
DER 30.3% <35%
Miss Rate 28.2% - -
False Alarm 0.9% - -
Speaker Error 1.2% - -
RTFx 17.8x >1.0x
Speakers 4/4 - -

Sortformer High-Latency • ES2004a • Runtime: 3m 9s • 2026-08-19T19:09:33.560Z

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

PocketTTS Smoke Test ✅

Check Result
Build
Model download
Model load
Synthesis pipeline
Output WAV ✅ (146.3 KB)

Runtime: 0m20s

Note: PocketTTS uses CoreML MLState (macOS 15) KV cache + Mimi streaming state. CI VM lacks physical GPU — audio quality and performance may differ from Apple Silicon.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

VAD Benchmark Results

Performance Comparison

Dataset Accuracy Precision Recall F1-Score RTFx Files
MUSAN 94.0% 89.3% 100.0% 94.3% 489.7x faster 50
VOiCES 94.0% 89.3% 100.0% 94.3% 495.5x faster 50

Dataset Details

  • MUSAN: Music, Speech, and Noise dataset - standard VAD evaluation
  • VOiCES: Voices Obscured in Complex Environmental Settings - tests robustness in real-world conditions

✅: Average F1-Score above 70%

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Speaker Diarization Benchmark Results

Speaker Diarization Performance

Evaluating "who spoke when" detection accuracy

Metric Value Target Status Description
DER 15.1% <30% Diarization Error Rate (lower is better)
JER 24.9% <25% Jaccard Error Rate
RTFx 27.50x >1.0x Real-Time Factor (higher is faster)

Diarization Pipeline Timing Breakdown

Time spent in each stage of speaker diarization

Stage Time (s) % Description
Model Download 14.144 37.1 Fetching diarization models
Model Compile 6.062 15.9 CoreML compilation
Audio Load 0.100 0.3 Loading audio file
Segmentation 11.446 30.0 Detecting speech regions
Embedding 19.077 50.0 Extracting speaker voices
Clustering 7.631 20.0 Grouping same speakers
Total 38.165 100 Full pipeline

Speaker Diarization Research Comparison

Research baselines typically achieve 18-30% DER on standard datasets

Method DER Notes
FluidAudio 15.1% On-device CoreML
Research baseline 18-30% Standard dataset performance

Note: RTFx shown above is from GitHub Actions runner. On Apple Silicon with ANE:

  • M2 MacBook Air (2022): Runs at 150 RTFx real-time
  • Performance scales with Apple Neural Engine capabilities

🎯 Speaker Diarization Test • AMI Corpus ES2004a • 1049.0s meeting audio • 38.2s diarization time • Test runtime: 2m 6s • 08/19/2026, 03:14 PM EST

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

ASR Benchmark Results ✅

Status: All benchmarks passed

Parakeet v3 (multilingual)

Dataset WER Avg WER Med RTFx Status
test-clean 0.57% 0.00% 4.33x
test-other 1.35% 0.00% 2.68x

Parakeet v2 (English-optimized)

Dataset WER Avg WER Med RTFx Status
test-clean 0.80% 0.00% 5.16x
test-other 1.56% 0.00% 3.22x

Streaming (v3)

Metric Value Description
WER 0.00% Word Error Rate in streaming mode
RTFx 0.53x Streaming real-time factor
Avg Chunk Time 1.719s Average time to process each chunk
Max Chunk Time 1.961s Maximum chunk processing time
First Token 2.062s Latency to first transcription token
Total Chunks 31 Number of chunks processed

Streaming (v2)

Metric Value Description
WER 0.00% Word Error Rate in streaming mode
RTFx 0.57x Streaming real-time factor
Avg Chunk Time 1.589s Average time to process each chunk
Max Chunk Time 2.348s Maximum chunk processing time
First Token 1.674s Latency to first transcription token
Total Chunks 31 Number of chunks processed

Streaming tests use 5 files with 0.5s chunks to simulate real-time audio streaming

25 files per dataset • Test runtime: 12m15s • 08/19/2026, 03:18 PM EST

RTFx = Real-Time Factor (higher is better) • Calculated as: Total audio duration ÷ Total processing time
Processing time includes: Model inference on Apple Neural Engine, audio preprocessing, state resets between files, token-to-text conversion, and file I/O
Example: RTFx of 2.0x means 10 seconds of audio processed in 5 seconds (2x faster than real-time)

Expected RTFx Performance on Physical M1 Hardware:

• M1 Mac: ~28x (clean), ~25x (other)
• CI shows ~0.5-3x due to virtualization limitations

Testing methodology follows HuggingFace Open ASR Leaderboard

…tion

Review fixes for ensurePackMimiEncoder:

- Cache acceptance now goes through ModelCache.isCacheComplete instead of
  bare directory existence. An interrupted download deliberately leaves
  *.partial staging files for byte-range resume; accepting such a bundle
  failed MLModel(contentsOf:) later without ever taking the
  shared-encoder fallback (same class as #819). A bundle still incomplete
  after the resume attempt is cleared and re-downloaded once from scratch
  (stale staging file next to complete weights — resume can't repair it),
  mirroring ModelHub.loadWithRecovery semantics; verified locally by
  planting a weight.bin.partial: detect -> clear -> re-download -> clone
  proceeds pack-local, warm cache stays a no-network fast path.

- Cancellation is no longer swallowed as an optional-download failure:
  the helper is throwing and rethrows via RetryPolicy.isCancellation, so
  a cancelled caller propagates instead of continuing into the fallback
  (or kicking off another download). Genuine availability/network
  failures still return nil and fall back.
@Alex-Wengg
Alex-Wengg merged commit 33285d2 into main Aug 19, 2026
11 checks passed
@Alex-Wengg
Alex-Wengg deleted the fix/793-per-language-clone-encoder branch August 19, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PocketTTS non-English languages Cloned voice

1 participant