Chinese language support#27
Open
krmanik wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Mandarin Chinese (zh-cn) support to KokoroSwift’s G2P pipeline (via MisakiZH) and adjusts model integration details to better match tokenization/weight naming expectations, alongside some local-package wiring changes.
Changes:
- Add
zhCNlanguage option and route Chinese phonemization through MisakiZH when available. - Update timestamp prediction to use tokenizer-derived token counts for alignment with
predictionDuration. - Normalize certain weight keys by stripping
*_module.prefixes; update SPM dependencies/products (including MisakiZH).
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
Sources/KokoroSwift/Utils/BenchmarkTimer.swift |
Adds a DEBUG-only benchmarking utility (no-op in RELEASE). |
Sources/KokoroSwift/TextProcessing/MisakiG2PProcessor.swift |
Extends Misaki-based G2P to support Mandarin via MisakiZH. |
Sources/KokoroSwift/TextProcessing/Language.swift |
Adds zhCN language case. |
Sources/KokoroSwift/TTSEngine/WeightLoader.swift |
Normalizes weight keys to handle *_module. prefixes. |
Sources/KokoroSwift/TTSEngine/TimestampPredictor.swift |
Aligns duration indexing with tokenizer token counts for phonemes/whitespace. |
Package.swift |
Switches some dependencies to local path: and adds MisakiZH product. |
Package.resolved |
Updates resolved dependency graph to match new package wiring. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+43
to
+49
| let spaceTokenCount = Tokenizer.tokenize(phonemizedText: t.whitespace).count | ||
| if spaceTokenCount > 0 { | ||
| let spaceDuration: Float = predictionDuration[i..<(i + spaceTokenCount)].sum().item() | ||
| left = right + spaceDuration | ||
| right = left + spaceDuration | ||
| i += spaceTokenCount | ||
| } |
Comment on lines
+66
to
+71
| let spaceTokenCount = t.whitespace.isEmpty ? 0 : Tokenizer.tokenize(phonemizedText: t.whitespace).count | ||
| let spaceDuration: Float = spaceTokenCount > 0 ? predictionDuration[j..<(j + spaceTokenCount)].sum().item() : 0.0 | ||
| left = right + (2.0 * tokenDuration) + spaceDuration | ||
| t.end_ts = Double(left / magicDivisor) | ||
| right = left + spaceDuration | ||
| i = j + (t.whitespace.isEmpty ? 0 : 1) | ||
| i = j + spaceTokenCount |
Comment on lines
40
to
+43
| for (key, value) in weights { | ||
| // Normalize key: strip _module suffix from top-level prefix | ||
| // e.g. "bert_module." -> "bert.", "predictor_module." -> "predictor." | ||
| let key = key.replacingOccurrences(of: "_module.", with: ".") |
| // Kokoro-tts-lib | ||
| // | ||
| import Foundation | ||
| import MisakiSwift |
Comment on lines
35
to
37
| func setLanguage(_ language: Language) throws { | ||
| currentLanguage = language | ||
| switch language { |
| /// Starts or restarts the timer for this timing measurement. | ||
| func startTimer() { | ||
| lock.lock() | ||
| start = DispatchTime.now() |
Comment on lines
+20
to
+21
| .package(path: "../MisakiSwift"), | ||
| .package(path: "../MLXUtilsLibrary") |
Comment on lines
32
to
34
| .product(name: "MisakiSwift", package: "MisakiSwift"), | ||
| .product(name: "MisakiZH", package: "MisakiSwift"), | ||
| .product(name: "MLXUtilsLibrary", package: "MLXUtilsLibrary") |
| // MLXUtilsLibrary | ||
| // | ||
| import Foundation | ||
| import MLX |
Comment on lines
+278
to
+279
| /// No-op in RELEASE builds - returns 0.0 | ||
| @inline(__always) public static func getTimeInSec(_ id: String) -> Double? { 0.0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After the pull request mlalma/MisakiSwift#9, then need to update for
.package(path:.The Chinese tts can be tested by using voices2.npz file in the test app, like this krmanik/KokoroTestApp@c875b51