Skip to content

Fix warnings for initializing tts lexicon. - #2823

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:fix-tts-lexicon-init
Nov 25, 2025
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:fix-tts-lexicon-init

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Nov 25, 2025 •

Copy link
Copy Markdown
Collaborator

To fix the following warnings

/Users/runner/work/sherpa-onnx/sherpa-onnx/sherpa-onnx/csrc/character-lexicon.cc:InitLexicon:300 Empty token ids for ''
/Users/runner/work/sherpa-onnx/sherpa-onnx/sherpa-onnx/csrc/character-lexicon.cc:InitLexicon:300 Empty token ids for ''
/Users/runner/work/sherpa-onnx/sherpa-onnx/sherpa-onnx/csrc/character-lexicon.cc:InitLexicon:300 Empty token ids for ''

Summary by CodeRabbit

  • Bug Fixes
    • Lexicon initialization now skips empty or whitespace-only lines, preventing spurious entries and improving robustness of lexicon loading and parsing. This reduces errors from malformed input and makes the lexicon processing more tolerant of imperfect source files.

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

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 25, 2025
@coderabbitai

coderabbitai Bot commented Nov 25, 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

During lexicon loading in InitLexicon, lines that are empty or contain only whitespace are now skipped early with a continue, so such lines are ignored without other logic changes.

Changes

Cohort / File(s) Summary
Whitespace-only line filtering
sherpa-onnx/csrc/character-lexicon.cc
Added an early continue to skip lines that are empty or contain only whitespace (spaces/tabs) in the InitLexicon loop.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

  • Review focus: the added condition in InitLexicon and any surrounding loop context for side effects.

Suggested labels

size:XS

Poem

I nibble through lines, gentle and quick,
Skipping the blanks with a hop and a flick.
Tabs and spaces, gone from the view,
Lexicon tidy—fresh as morning dew. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix warnings for initializing tts lexicon' directly addresses the main objective of the pull request, which is to fix warnings produced during lexicon initialization by skipping empty or whitespace-only lines.

📜 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 2f57e6a and 4a043cc.

📒 Files selected for processing (1)
  • sherpa-onnx/csrc/character-lexicon.cc (1 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.

@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 focuses on improving the robustness of the TTS lexicon initialization process by eliminating a recurring warning. The change ensures that the lexicon parser correctly handles and ignores empty or whitespace-only lines, leading to cleaner log output and more reliable lexicon loading.

Highlights

  • Warning Fix: Addresses and resolves warnings related to 'Empty token ids' that occurred during the initialization of the Text-to-Speech (TTS) lexicon.
  • Lexicon Parsing Improvement: Introduces a check to explicitly skip lines that are empty or contain only whitespace characters when parsing the lexicon file, preventing erroneous processing.
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 addresses a warning that occurs when processing empty lines in a lexicon file. The fix involves adding a check to skip lines that are empty or contain only whitespace. This is a good approach. I've added one suggestion to make the whitespace check more robust by including all standard whitespace characters, which will prevent potential issues with files from different operating systems (e.g., Windows line endings).

Comment thread sherpa-onnx/csrc/character-lexicon.cc Outdated
Comment on lines +269 to +272
if (line.find_first_not_of(" \t") == std::string::npos) {
// Line is empty or only spaces/tabs, skip it
continue;
}

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

The check for whitespace lines is a good addition to prevent warnings with empty or whitespace-only lines. However, it only considers spaces and tabs. It would be more robust to check for all standard whitespace characters, including carriage return (\r), which can be present in files with Windows-style line endings (\r\n).

      if (line.find_first_not_of(" \t\n\v\f\r") == std::string::npos) {
        // Line is empty or contains only whitespace, skip it
        continue;
      }

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
sherpa-onnx/csrc/character-lexicon.cc (1)

269-272: LGTM! This correctly fixes the reported warnings.

The early continue for whitespace-only lines prevents the "Empty token ids for ''" warnings by skipping lines that have no actual content before they're processed. The logic is sound and the implementation is clean.

Optional: Consider including \r in the whitespace check for cross-platform robustness.

While the current fix addresses the reported issue, Windows-style line endings might leave \r characters in the string. You could enhance robustness by checking for carriage returns as well:

-      if (line.find_first_not_of(" \t") == std::string::npos) {
-        // Line is empty or only spaces/tabs, skip it
+      if (line.find_first_not_of(" \t\r") == std::string::npos) {
+        // Line is empty or only whitespace, skip it
         continue;
       }

This is a minor refinement and not strictly necessary for the stated problem.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9871306 and 2f57e6a.

📒 Files selected for processing (1)
  • sherpa-onnx/csrc/character-lexicon.cc (1 hunks)

@csukuangfj
csukuangfj merged commit 3c79bda into k2-fsa:master Nov 25, 2025
38 of 43 checks passed
@csukuangfj
csukuangfj deleted the fix-tts-lexicon-init branch November 25, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant