fix: KokoroAne zh-CN noise reduction via atan2 phase correction#569
fix: KokoroAne zh-CN noise reduction via atan2 phase correction#569Alex-Wengg wants to merge 2 commits into
Conversation
Documents the regenerated `KokoroNoise.mlmodelc` from mobius PR #50, which fixes audible high-frequency background noise (most noticeable on zh voices) via an atan2 phase correction in `CoreMLForwardSTFT`. Model I/O contract is unchanged so no Swift update is needed. Adds a cache-invalidation note for users who ran KokoroAne before the fix — the downloader does file-existence checks only, so a stale `KokoroNoise.mlmodelc` won't be re-fetched without manual deletion.
PocketTTS Smoke Test ✅
Runtime: 0m21s 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. |
Kokoro TTS Smoke Test ✅
Runtime: 0m46s Note: Kokoro TTS uses CoreML flow matching + Vocos vocoder. CI VM lacks physical ANE — performance may differ from Apple Silicon. |
Qwen3-ASR int8 Smoke Test ✅
Performance Metrics
Runtime: 3m25s Note: CI VM lacks physical GPU — CoreML MLState (macOS 15) KV cache produces degraded results on virtualized runners. On Apple Silicon: ~1.3% WER / 2.5x RTFx. |
ASR Benchmark Results ✅Status: All benchmarks passed Parakeet v3 (multilingual)
Parakeet v2 (English-optimized)
Streaming (v3)
Streaming (v2)
Streaming tests use 5 files with 0.5s chunks to simulate real-time audio streaming 25 files per dataset • Test runtime: 5m45s • 05/03/2026, 08:00 PM EST RTFx = Real-Time Factor (higher is better) • Calculated as: Total audio duration ÷ Total processing time Expected RTFx Performance on Physical M1 Hardware:• M1 Mac: ~28x (clean), ~25x (other) Testing methodology follows HuggingFace Open ASR Leaderboard |
Speaker Diarization Benchmark ResultsSpeaker Diarization PerformanceEvaluating "who spoke when" detection accuracy
Diarization Pipeline Timing BreakdownTime spent in each stage of speaker diarization
Speaker Diarization Research ComparisonResearch baselines typically achieve 18-30% DER on standard datasets
Note: RTFx shown above is from GitHub Actions runner. On Apple Silicon with ANE:
🎯 Speaker Diarization Test • AMI Corpus ES2004a • 1049.0s meeting audio • 56.1s diarization time • Test runtime: 2m 31s • 05/03/2026, 07:53 PM EST |
VAD Benchmark ResultsPerformance Comparison
Dataset Details
✅: Average F1-Score above 70% |
Parakeet EOU Benchmark Results ✅Status: Benchmark passed Performance Metrics
Streaming Metrics
Test runtime: 0m48s • 05/03/2026, 07:47 PM EST RTFx = Real-Time Factor (higher is better) • Processing includes: Model inference, audio preprocessing, state management, and file I/O |
Offline VBx Pipeline ResultsSpeaker Diarization Performance (VBx Batch Mode)Optimal clustering with Hungarian algorithm for maximum accuracy
Offline VBx Pipeline Timing BreakdownTime spent in each stage of batch diarization
Speaker Diarization Research ComparisonOffline VBx achieves competitive accuracy with batch processing
Pipeline Details:
🎯 Offline VBx Test • AMI Corpus ES2004a • 1049.0s meeting audio • 96.9s processing • Test runtime: 1m 39s • 05/03/2026, 07:41 PM EST |
Sortformer High-Latency Benchmark ResultsES2004a Performance (30.4s latency config)
Sortformer High-Latency • ES2004a • Runtime: 3m 37s • 2026-05-03T23:44:39.126Z |
Chronological log covering THCHS-30 benchmark, error analysis, beam search A/B, Cohere encoder fix, the Kokoro v1.1-zh atan2 noise root-cause investigation, the Devin review audit, and PRs landed.
## Summary Phase 1 — variant plumbing + phonemes-bypass synthesis for Kokoro-82M-v1.1-zh on the existing 7-stage CoreML chain. Callers that supply pre-computed Bopomofo (e.g. via misaki[zh] in Python or a future Swift G2P) can now synthesize Mandarin audio. Mandarin text-to-Bopomofo G2P is deferred to a separate Phase 2 PR. The 7-stage chain is **language-agnostic by construction** — input ids, voice slices, and per-stage I/O contracts are identical across v1.0 (English) and v1.1-zh (Mandarin). Only the embedding vocab (177 → 171), the HF subdir (`ANE/` → `ANE-zh/`), the voice-file layout (flat → `voices/<voice>.bin`), and the default voice (`af_heart` → `zf_001`) differ. ## Changes - New `Repo.kokoroAneZh` → `FluidInference/kokoro-82m-coreml/ANE-zh` with `subPath = ANE-zh`, `folderName = kokoro-82m-coreml/ANE-zh`. - `ModelNames.KokoroAne.requiredModelsZh` references `voices/zf_001.bin` so the downloader's all-files-present check resolves correctly when the file lands at `<repoDir>/voices/zf_001.bin`. - New `KokoroAneVariant` enum (`.english` / `.mandarin`) with `defaultVoice`, `useVoicesSubdir`, and `repo` accessors. - `KokoroAneResourceDownloader.ensureModels` and `ensureVoicePack` accept a `variant` param (default `.english` keeps existing callers source-compatible). Mandarin voice fetch creates the `voices/` parent directory on demand. - `KokoroAneModelStore` and `KokoroAneManager` thread the variant through to download + load. - `KokoroAneManager.synthesize(text:)` and `synthesizeDetailed(text:)` reject Mandarin with a clear error directing callers to `synthesizeFromPhonemes()`. The phonemes-bypass entry point already works for any vocab via `vocab.encode → 7-stage chain`. - CLI `--variant` flag accepts `en` / `english` / `zh` / `mandarin` for the `kokoro-ane` backend. Mandarin runs treat the input text as pre-computed Bopomofo and call `synthesizeFromPhonemesDetailed`. - 12 new unit tests (`KokoroAneVariantTests`): variant defaults, repo wiring, required-files set routing, manager init signatures, and Mandarin text-path rejection on both `synthesize` and `synthesizeDetailed`. End-to-end Mandarin synthesis verified against PyTorch ground truth on `zf_001` and `zm_009`. Background-noise investigation tracked separately in #569 (atan2 phase correction in upstream `CoreMLForwardSTFT`). ## Test plan - [x] `swift build` clean - [x] `swift test --filter KokoroAneVariantTests` — 12/12 pass - [x] `swift format lint` clean (only pre-existing warnings on `fastV2_1`/`balancedV2_1`/`highContextV2_1` enum cases unrelated to this PR) - [ ] After HF upload of `ANE-zh/` bundle, end-to-end smoke test: `swift run fluidaudiocli tts "ㄋㄧˇㄏㄠˇㄕˋㄐㄧㄝˋ。" --backend kokoro-ane --variant zh --voice zf_001 --output /tmp/zh.wav` - [ ] No regressions on existing English path (default-arg behavior preserved) ## Out of scope - Mandarin text-to-Bopomofo G2P — Phase 2 (separate PR). - HF upload of `ANE-zh/` bundle — handled outside this repo. - Updating `Documentation/` with Mandarin voice list — defer to Phase 2 when the path is fully usable end-to-end.
Summary
Documents the regenerated
KokoroNoise.mlmodelcnow live on HuggingFace atFluidInference/kokoro-82m-coreml/ANE/, which eliminates audible high-frequency background noise that was most noticeable on Mandarin (zh) synthesis.No Swift code changes are required — the fix is entirely in the model conversion.
Root cause
CoreMLForwardSTFTinmobius/models/tts/kokoro/laishere-coreml/convert-coreml.pyreconstructed phase from real/imaginary parts in a way that produced an audible HF noise floor on the synthesizer's source signal. The noise survived every weight-quantization, compute-precision, and dispatch-mode change tried during conversion, which is why it shipped in the first KokoroAne release.Fix
mobius PR #50 replaces the manual phase reconstruction with
atan2(imag, real)so the inverse-STFT phase is computed correctly. The outputKokoroNoise.mlmodelckeeps the same:KokoroNoise.mlmodelc)F0_curvefp32,style_timbrefp32)x_source_0,x_source_1)so the existing
KokoroAneSynthesizerNoise stage call site atKokoroAneSynthesizer.swift:108-113consumes the regenerated model unchanged.Distribution
The fixed
KokoroNoise.mlmodelcis now uploaded toFluidInference/kokoro-82m-coreml/ANE/. Fresh installs pick it up automatically on firstKokoroAneManager.initialize().Cache invalidation for existing users
KokoroAneResourceDownloader.ensureModelsonly checks file existence, not version/etag/hash, so users who ran KokoroAne before the fix landed will keep using the stale local copy. The fix for them is to delete the cached bundle:The next
initialize()will re-download the corrected file.Changes
Documentation/TTS/KokoroAne.md— new "Model Updates" section explaining the atan2 phase correction and the cache-invalidation step for existing users.Test plan
git diff main --stat)