Skip to content

Chinese language support#27

Open
krmanik wants to merge 4 commits into
mlalma:mainfrom
krmanik:main
Open

Chinese language support#27
krmanik wants to merge 4 commits into
mlalma:mainfrom
krmanik:main

Conversation

@krmanik

@krmanik krmanik commented Feb 20, 2026

Copy link
Copy Markdown

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

Copilot AI review requested due to automatic review settings April 25, 2026 04:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 zhCN language 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 thread Package.swift
Comment on lines +20 to +21
.package(path: "../MisakiSwift"),
.package(path: "../MLXUtilsLibrary")
Comment thread Package.swift
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 }
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.

2 participants