Skip to content

Build APKs for MatchaTTS Chinese+English - #2882

Merged
csukuangfj merged 3 commits into
k2-fsa:masterfrom
csukuangfj:apk-matcha-zh-en
Dec 10, 2025
Merged

csukuangfj merged 3 commits into
k2-fsa:masterfrom
csukuangfj:apk-matcha-zh-en

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Dec 10, 2025 •

Copy link
Copy Markdown
Collaborator
Screenshot 2025-12-10 at 15 22 17 https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine-cn.html

Summary by CodeRabbit

  • New Features

    • Added support for matcha-icefall Chinese-English text-to-speech model with configuration examples.
  • Documentation

    • Added example configurations for the new Chinese-English TTS model.
  • Chores

    • Updated build configuration to support the new model variant.
    • Updated ignore patterns.

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 10, 2025
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @csukuangfj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates the matcha-icefall-zh-en Text-to-Speech model, enabling its use within the Sherpa ONNX Android applications. The changes include necessary updates to build scripts for proper language handling, the addition of example configurations to facilitate model adoption, and significant refinements to the audio playback system using Kotlin coroutines for more robust and efficient sample processing.

Highlights

  • New Model Integration: Introduced comprehensive support for the matcha-icefall-zh-en (Chinese+English) Text-to-Speech model, including its configuration and build process.
  • Android Application Updates: Added commented-out example configurations for the new matcha-icefall-zh-en model in both the SherpaOnnxTts and SherpaOnnxTtsEngine Android applications, demonstrating how to use it.
  • Coroutine and Audio Playback Refinements: Enhanced the audio playback mechanism in the TTS engine by adopting a SupervisorJob for improved coroutine management, increasing the samplesChannel capacity, and refining the logic for processing and draining audio samples.
  • Build Script and Model Configuration Enhancements: Updated the APK build scripts to correctly set the language for the matcha-icefall-zh-en model and streamlined model configuration in the Python script by removing redundant dict_dir assignments for several TTS models.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds support for building APKs for the MatchaTTS Chinese+English model. The changes include updates to the build scripts, example configurations in the Android apps, and significant refactoring of coroutine and channel handling in the SherpaOnnxTtsEngine's MainActivity. The coroutine management improvements are good, but I've identified a couple of issues with the channel communication logic that could lead to hangs or data loss. I've provided specific suggestions to address these. Additionally, I've suggested a small refactoring in the shell scripts to improve maintainability.

Comment on lines +340 to +341
val ok = samplesChannel.trySend(samplesCopy).isSuccess
Log.i(TAG, "callback called with $ok")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While logging the success status of trySend is useful for debugging, the log message could be more informative, especially for the failure case. When trySend fails, audio samples are dropped, which can lead to degraded audio quality. It would be better to log this as a warning to highlight the data loss.

Consider checking the return value and logging a warning if the send operation was not successful.

                val ok = samplesChannel.trySend(samplesCopy).isSuccess
                if (!ok) {
                    Log.w(TAG, "Channel buffer is full. Dropping audio samples.")
                }

Comment on lines +116 to +118
if [[ $model_dir == matcha-icefall-zh-en ]]; then
lang=zh_en
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This adds another if block to set lang=zh_en. To improve readability and maintainability, consider grouping all conditions that set lang to zh_en into a single control structure, like a case statement. This would make the script easier to read and modify in the future.

For example:

case $model_dir in
  vits-melo-tts-zh_en|\
  matcha-icefall-zh-en|\
  kokoro-multi-lang-v1_0|\
  kokoro-multi-lang-v1_1|\
  kokoro-int8-multi-lang-v1_1)
    lang=zh_en
    ;;
esac

Comment on lines +110 to +112
if [[ $model_dir == matcha-icefall-zh-en ]]; then
lang=zh_en
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This adds another if block to set lang=zh_en. To improve readability and maintainability, consider grouping all conditions that set lang to zh_en into a single control structure, like a case statement. This would make the script easier to read and modify in the future.

For example:

case $model_dir in
  vits-melo-tts-zh_en|\
  matcha-icefall-zh-en|\
  kokoro-multi-lang-v1_0|\
  kokoro-multi-lang-v1_1|\
  kokoro-int8-multi-lang-v1_1)
    lang=zh_en
    ;;
esac

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 10, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR adds support for the Matcha-icefall Chinese-English (zh-en) TTS model by introducing configuration examples in Android apps, build script conditionals for language assignment, a new model group definition in the Python build generator, and an updated gitignore pattern.

Changes

Cohort / File(s) Summary
Git configuration
.gitignore
Added ignore pattern for matcha-icefall files
Android TTS app documentation
android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt,
android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt
Added Example 12 configuration block documenting the Matcha-icefall zh-en model with modelDir, acousticModelName, vocoder, dataDir, and lexicon fields
Android TTS engine runtime
android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/MainActivity.kt
Introduced persistent CoroutineScope with fixed-capacity samplesChannel (128); replaced direct CoroutineScope launches with scope.launch; refactored channel draining logic; added async sample array submission and trySend in callback with logging
APK build scripts
scripts/apk/build-apk-tts.sh.in,
scripts/apk/build-apk-tts-engine.sh.in
Added conditional to assign lang=zh_en when model_dir equals matcha-icefall-zh-en, mirroring existing language-code handling
APK build generator
scripts/apk/generate-tts-apk-script.py
Removed dict_dir assignments for Chinese models; introduced new chinese_english_models group in get_matcha_models() with lexicon, rule_fsts, vocoder, and data_dir; expanded model aggregation to include the new group

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Python script (generate-tts-apk-script.py): Verify the new chinese_english_models group is correctly integrated with all required fields and that removal of dict_dir does not break existing models
  • Shell scripts (build-apk-tts*.sh.in): Confirm the matcha-icefall-zh-en conditional is placed correctly relative to other language-code assignments and does not create unintended branch precedence
  • Android CoroutineScope refactoring (MainActivity.kt in TtsEngine): Review the channel capacity (128), async sample submission logic, and trySend usage to ensure thread-safety and proper error handling

Possibly related PRs

Suggested labels

size:L

Poem

🐰 A matcha brew with voices blending,
Chinese whispers, English portending,
zh-en flows through channels wide,
Coroutines dance with measured stride,
Tea leaves steep in code so fine! 🍵

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fdd509 and 74422e0.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt (1 hunks)
  • android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/MainActivity.kt (7 hunks)
  • android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt (1 hunks)
  • scripts/apk/build-apk-tts-engine.sh.in (1 hunks)
  • scripts/apk/build-apk-tts.sh.in (1 hunks)
  • scripts/apk/generate-tts-apk-script.py (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@csukuangfj
csukuangfj merged commit afa5928 into k2-fsa:master Dec 10, 2025
1 check was pending
@csukuangfj
csukuangfj deleted the apk-matcha-zh-en branch December 10, 2025 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant