Skip to content

测试添加标点 - #3037

Closed
jilinmo1 wants to merge 1 commit into
k2-fsa:masterfrom
jilinmo1:master
Closed

jilinmo1 wants to merge 1 commit into
k2-fsa:masterfrom
jilinmo1:master

Conversation

@jilinmo1

@jilinmo1 jilinmo1 commented Jan 13, 2026 •

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Introduced comprehensive punctuation processing functionality to automatically add and format punctuation in text
    • Added dual-mode support for both offline and online punctuation processing to accommodate different use cases
    • Added interactive testing capability in the user interface to help users validate punctuation features

✏️ 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 Jan 13, 2026
@coderabbitai

coderabbitai Bot commented Jan 13, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR integrates offline and online punctuation support into the HarmonyOS SherpaOnnx project by adding native C++ API bindings, TypeScript/ETS wrapper classes, public module exports, updated package dependencies, and a test implementation that demonstrates punctuation processing functionality.

Changes

Cohort / File(s) Summary
Package Configuration
harmony-os/SherpaOnnxHar/entry/oh-package.json5
Added local file dependency for sherpa_onnx package
Native API Bindings
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts
Declared four new native punctuation methods: createOnlinePunctuation, createOfflinePunctuation, offlinePunctuationAddPunct, onlinePunctuationAddPunct
ETS Public API
harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets
Re-exported OfflinePunctuation and OfflinePunctuationModelConfig types
Punctuation Implementation
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets
Added four new public classes: OnlinePunctuationModelConfig, OfflinePunctuationConfig, OfflinePunctuationModelConfig, OfflinePunctuation with configuration and punctuation processing capability
Component Integration
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingAsr.ets
Imported createOfflinePunctuation and offlinePunctuationAddPunct from native bindings
Test Implementation
harmony-os/SherpaOnnxHar/entry/src/main/ets/pages/Index.ets
Added test() method and UI interaction handler demonstrating offline punctuation model instantiation and text punctuation processing

Sequence Diagram

sequenceDiagram
    participant UI as Index Component
    participant Punct as OfflinePunctuation
    participant Native as libsherpa_onnx (Native)
    
    UI->>Punct: new OfflinePunctuation(modelConfig)
    activate Punct
    Punct->>Native: createOfflinePunctuation(config)
    Native-->>Punct: handle
    Punct->>Punct: store handle
    deactivate Punct
    
    UI->>Punct: offlinePunctuationAddPunct(text)
    activate Punct
    Punct->>Native: offlinePunctuationAddPunct(handle, text)
    Native-->>Punct: punctuated_text
    Punct-->>UI: punctuated_text
    deactivate Punct
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • k2-fsa/sherpa-onnx#2759: Adds corresponding punctuation APIs and native C/C++ symbols for online and offline punctuation functionality
  • k2-fsa/sherpa-onnx#2510: Provides the C++ binding layer that this PR's TypeScript/ETS exports depend on for native punctuation operations

Suggested labels

size:L

Suggested reviewers

  • csukuangfj

Poem

🐰 Whiskers twitch with punctuation cheer,
Offline dots and commas appear!
Native bindings dance in harmony,
Text flows sweetly, oh what a symphony!
Punctuation magic, now crystal clear! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '测试添加标点' (Test adding punctuation) accurately describes the main functionality added: punctuation support infrastructure with a test implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 @jilinmo1, 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!

此拉取请求旨在为 HarmonyOS 上的 SherpaOnnxHar 应用引入标点处理能力。通过集成离线标点模块,并提供一个基础的UI测试入口,它为提升语音识别结果的文本可读性奠定了基础,使得处理后的文本更符合语言规范。

Highlights

  • 新增标点功能: 引入了离线标点(OfflinePunctuation)功能,允许对文本进行自动标点处理。
  • 依赖更新: 在 entry 模块的 oh-package.json5 中添加了对 sherpa_onnx 库的本地文件依赖。
  • 示例页面更新: 修改了 Index.ets 页面,添加了一个点击事件,用于演示离线标点功能的调用和测试。
  • 核心库接口扩展: 在 libsherpa_onnx 的类型定义中新增了创建和使用在线/离线标点功能的接口,并在 NonStreamingAsr.ets 和 StreamingAsr.ets 中导入了这些接口。
  • 标点配置类定义: 在 StreamingAsr.ets 中定义了 OnlinePunctuationModelConfig、OfflinePunctuationConfig 和 OfflinePunctuationModelConfig 等配置类,以及 OfflinePunctuation 类来封装离线标点逻辑。
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. ↩

@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: 4

🤖 Fix all issues with AI agents
In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts:
- Around line 30-34: The parameter lists for offlinePunctuationAddPunct and
onlinePunctuationAddPunct are missing a space after the comma; update their
declarations so the comma is followed by a space (e.g., change "(handle:
object,text: string)" to "(handle: object, text: string)") to match the file's
existing formatting conventions used by functions like createOnlinePunctuation
and createOfflinePunctuation.

In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingAsr.ets:
- Around line 8-9: Remove the unused imports createOfflinePunctuation and
offlinePunctuationAddPunct from the import list in NonStreamingAsr.ets; locate
the import statement that includes these symbols and delete them so only used
symbols remain (they are used in StreamingAsr.ets and not referenced in
NonStreamingAsr).

In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets:
- Around line 99-113: The constructor in class OfflinePunctuation uses a
misleading variable name `onlineConfig`; rename it to `offlineConfig` throughout
the constructor to match the class semantics: update the declaration
(OfflinePunctuationConfig), the assignment `offlineConfig.model = config`, and
the call to `createOfflinePunctuation(offlineConfig)` so all references inside
the constructor (in OfflinePunctuation) are consistently `offlineConfig`.
🧹 Nitpick comments (4)
harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets (1)

40-41: Consider module organization: "Offline" exports from "StreamingAsr".

The exports look correct, but semantically it's unusual to export OfflinePunctuation and OfflinePunctuationModelConfig from StreamingAsr (which typically implies online/streaming). Consider whether these belong in NonStreamingAsr for consistency with the naming convention used elsewhere (e.g., OfflineRecognizer in NonStreamingAsr).

harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets (3)

11-12: Unused imports detected.

createOnlinePunctuation and onlinePunctuationAddPunct are imported but never used in this file. Consider removing them to keep the imports clean, or add the corresponding OnlinePunctuation class implementation if intended.


44-48: Inconsistent naming convention.

Properties cnn_bilstm and bpe_vocab use snake_case, while other config classes in this file use camelCase (e.g., numThreads, bpeVocab in OnlineModelConfig). If this is intentional to match native API field names, consider adding a comment to clarify; otherwise, align with the existing camelCase convention.


118-118: Commented-out code for punctuation integration.

Multiple commented-out lines (118, 149, 155-156, 191) indicate incomplete integration of punctuation into OnlineRecognizer. If this is intentional scaffolding for future work, consider:

  1. Adding a TODO comment explaining the plan, or
  2. Removing the commented code and implementing it in a follow-up PR.

Leaving unexplained commented code makes it unclear whether this is dead code or pending work.

Also applies to: 149-149, 155-156, 191-191

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9ff170 and ff145b1.

📒 Files selected for processing (6)
  • harmony-os/SherpaOnnxHar/entry/oh-package.json5
  • harmony-os/SherpaOnnxHar/entry/src/main/ets/pages/Index.ets
  • harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingAsr.ets
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets
🧰 Additional context used
🧬 Code graph analysis (1)
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts (3)
nodejs-addon-examples/test_asr_non_streaming_nemo_canary.js (1)
  • config (6-27)
nodejs-examples/test-offline-nemo-canary.js (2)
  • config (10-25)
  • text (39-39)
sherpa-onnx/csrc/lexicon.cc (2)
  • text (164-164)
  • text (269-269)
🔇 Additional comments (2)
harmony-os/SherpaOnnxHar/entry/oh-package.json5 (1)

8-10: LGTM!

The local package dependency reference is correctly configured to point to the sibling sherpa_onnx module.

harmony-os/SherpaOnnxHar/entry/src/main/ets/pages/Index.ets (1)

17-22: LGTM for test UI.

The click handler properly invokes the test method to exercise the punctuation functionality.

Comment on lines +6 to +12
test(){
const modelConfig = new OfflinePunctuationModelConfig();
const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;
let punctuation: OfflinePunctuation = new OfflinePunctuation(modelConfig)
let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you 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.

⚠️ Potential issue | 🟡 Minor

Test result is discarded without any feedback.

The punctuation result on line 11 is stored in text but never used (not logged, displayed, or returned). For testing purposes, consider adding console.log(text) or displaying the result to verify the functionality works correctly.

Additionally, there's no error handling if the model files are missing or the punctuation operation fails.

Suggested improvement
   test(){
     const modelConfig = new OfflinePunctuationModelConfig();
     const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
     modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;
     let punctuation: OfflinePunctuation = new OfflinePunctuation(modelConfig)
     let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you ok谢谢你')
+    console.log('Punctuated text:', text);
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test(){
const modelConfig = new OfflinePunctuationModelConfig();
const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;
let punctuation: OfflinePunctuation = new OfflinePunctuation(modelConfig)
let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you ok谢谢你')
}
test(){
const modelConfig = new OfflinePunctuationModelConfig();
const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;
let punctuation: OfflinePunctuation = new OfflinePunctuation(modelConfig)
let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you ok谢谢你')
console.log('Punctuated text:', text);
}

Comment on lines +30 to +34
export const createOnlinePunctuation: (config: object) => object;
export const createOfflinePunctuation: (config: object) => object;
export const offlinePunctuationAddPunct: (handle: object,text: string) => string;
export const onlinePunctuationAddPunct: (handle: object,text: string) => string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check if the Index.d.ts file exists and read it to verify the formatting inconsistency
fd Index.d.ts

Repository: k2-fsa/sherpa-onnx

Length of output: 143


🏁 Script executed:

# Search for the specific file and read relevant lines
find . -name "Index.d.ts" -type f -exec cat -n {} +

Repository: k2-fsa/sherpa-onnx

Length of output: 6478


🏁 Script executed:

# Search for onlinePunctuation usage across the repository
rg -n "onlinePunctuation" --type ts

Repository: k2-fsa/sherpa-onnx

Length of output: 227


🏁 Script executed:

# Also search in JavaScript/TypeScript files more broadly
rg -n "onlinePunctuation" -t js -t ts -t tsx -t jsx

Repository: k2-fsa/sherpa-onnx

Length of output: 89


🏁 Script executed:

# Search for createOnlinePunctuation specifically
rg -n "createOnlinePunctuation"

Repository: k2-fsa/sherpa-onnx

Length of output: 556


Missing space after comma in parameter lists.

Lines 32-33 are missing a space after the comma in the parameter list, inconsistent with other function declarations in this file (e.g., lines 6, 13, 63).

Formatting fix
-export const offlinePunctuationAddPunct: (handle: object,text: string) => string;
-export const onlinePunctuationAddPunct: (handle: object,text: string) => string;
+export const offlinePunctuationAddPunct: (handle: object, text: string) => string;
+export const onlinePunctuationAddPunct: (handle: object, text: string) => string;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const createOnlinePunctuation: (config: object) => object;
export const createOfflinePunctuation: (config: object) => object;
export const offlinePunctuationAddPunct: (handle: object,text: string) => string;
export const onlinePunctuationAddPunct: (handle: object,text: string) => string;
export const createOnlinePunctuation: (config: object) => object;
export const createOfflinePunctuation: (config: object) => object;
export const offlinePunctuationAddPunct: (handle: object, text: string) => string;
export const onlinePunctuationAddPunct: (handle: object, text: string) => string;
🤖 Prompt for AI Agents
In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts
around lines 30 - 34, The parameter lists for offlinePunctuationAddPunct and
onlinePunctuationAddPunct are missing a space after the comma; update their
declarations so the comma is followed by a space (e.g., change "(handle:
object,text: string)" to "(handle: object, text: string)") to match the file's
existing formatting conventions used by functions like createOnlinePunctuation
and createOfflinePunctuation.

Comment on lines +8 to +9
createOfflinePunctuation,
offlinePunctuationAddPunct,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify if these imports are used in NonStreamingAsr.ets
echo "=== Checking usage in NonStreamingAsr.ets ==="
rg -n "createOfflinePunctuation|offlinePunctuationAddPunct" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingAsr.ets

echo "=== Checking where these are actually used ==="
rg -n "createOfflinePunctuation|offlinePunctuationAddPunct" --type-add 'ets:*.ets' --type ets harmony-os/

echo "=== Checking if they are used in StreamingAsr.ets specifically ==="
rg -n "createOfflinePunctuation|offlinePunctuationAddPunct" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets

Repository: k2-fsa/sherpa-onnx

Length of output: 1968


Remove unused imports from this file.

createOfflinePunctuation and offlinePunctuationAddPunct are imported but never used in NonStreamingAsr.ets. These imports are used in StreamingAsr.ets, so they can be safely removed here.

🤖 Prompt for AI Agents
In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingAsr.ets
around lines 8 - 9, Remove the unused imports createOfflinePunctuation and
offlinePunctuationAddPunct from the import list in NonStreamingAsr.ets; locate
the import statement that includes these symbols and delete them so only used
symbols remain (they are used in StreamingAsr.ets and not referenced in
NonStreamingAsr).

Comment on lines +99 to +113
export class OfflinePunctuation {
public handle: object;
// public config: OfflinePunctuationConfig

constructor(config: OfflinePunctuationModelConfig) {
let onlineConfig = new OfflinePunctuationConfig()
onlineConfig.model = config
this.handle = createOfflinePunctuation(onlineConfig)
}

offlinePunctuationAddPunct(text: string): string {
let result = offlinePunctuationAddPunct(this.handle, text)
return result
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets | head -120 | tail -30

Repository: k2-fsa/sherpa-onnx

Length of output: 1208


🏁 Script executed:

# Search for destructor/cleanup patterns in the codebase
rg -A 5 "destructor|destroy\(\)|cleanup|release\(\)|free\(\)" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/ --type ts

Repository: k2-fsa/sherpa-onnx

Length of output: 44


🏁 Script executed:

# Check for similar native handle patterns in the file
rg -B 5 -A 5 "createOfflinePunctuation|createOnlineRecognizer|handle.*createOn" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets

Repository: k2-fsa/sherpa-onnx

Length of output: 1465


🏁 Script executed:

# Look at the entire OfflinePunctuation class and surrounding context
sed -n '90,120p' harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets

Repository: k2-fsa/sherpa-onnx

Length of output: 1041


🏁 Script executed:

# Search for any release, destroy, or free calls on handles
rg "handle.*release|handle.*destroy|handle.*free|\.release\(|\.destroy\(|\.free\(" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/ --type ts

Repository: k2-fsa/sherpa-onnx

Length of output: 44


🏁 Script executed:

# Check if there's documentation or comments about resource management
rg -i "resource|cleanup|garbage|collect|leak|release|free|destructor" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/ --type ts

Repository: k2-fsa/sherpa-onnx

Length of output: 44


🏁 Script executed:

# Search the entire StreamingAsr.ets for any cleanup patterns or comments
rg -i "cleanup|release|destroy|free|leak" harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets

Repository: k2-fsa/sherpa-onnx

Length of output: 44


🏁 Script executed:

# Check the native library binding or any .d.ts files that might document cleanup
find harmony-os/SherpaOnnxHar -name "*.d.ts" -o -name "*libsherpa*" | head -20

Repository: k2-fsa/sherpa-onnx

Length of output: 214


🏁 Script executed:

cat -n harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/types/libsherpa_onnx/Index.d.ts

Repository: k2-fsa/sherpa-onnx

Length of output: 6478


🏁 Script executed:

# Also check if there's a README or documentation about the library
find harmony-os/SherpaOnnxHar -name "README*" -o -name "*.md" | grep -E "(README|doc)" | head -10

Repository: k2-fsa/sherpa-onnx

Length of output: 294


🏁 Script executed:

# Check README files for any documentation about resource management
grep -i "cleanup\|release\|destroy\|free\|resource\|leak\|garbage" harmony-os/SherpaOnnxHar/README.md harmony-os/SherpaOnnxHar/sherpa_onnx/README.md

Repository: k2-fsa/sherpa-onnx

Length of output: 44


🏁 Script executed:

# Check the C API README which might have documentation
head -100 harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/include/sherpa-onnx/c-api/README.md

Repository: k2-fsa/sherpa-onnx

Length of output: 389


🏁 Script executed:

# Check if there are any Java or Kotlin examples that might show cleanup patterns
find harmony-os -name "*.java" -o -name "*.kt" | xargs grep -l "OfflinePunctuation" 2>/dev/null | head -5

Repository: k2-fsa/sherpa-onnx

Length of output: 44


Misleading variable name: onlineConfig should be offlineConfig.

Line 104 uses onlineConfig for the OfflinePunctuation class, which is inconsistent and confusing. Rename it to offlineConfig for clarity:

Proposed fix
  constructor(config: OfflinePunctuationModelConfig) {
-   let onlineConfig = new OfflinePunctuationConfig()
-   onlineConfig.model = config
-   this.handle = createOfflinePunctuation(onlineConfig)
+   let offlineConfig = new OfflinePunctuationConfig()
+   offlineConfig.model = config
+   this.handle = createOfflinePunctuation(offlineConfig)
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export class OfflinePunctuation {
public handle: object;
// public config: OfflinePunctuationConfig
constructor(config: OfflinePunctuationModelConfig) {
let onlineConfig = new OfflinePunctuationConfig()
onlineConfig.model = config
this.handle = createOfflinePunctuation(onlineConfig)
}
offlinePunctuationAddPunct(text: string): string {
let result = offlinePunctuationAddPunct(this.handle, text)
return result
}
}
export class OfflinePunctuation {
public handle: object;
// public config: OfflinePunctuationConfig
constructor(config: OfflinePunctuationModelConfig) {
let offlineConfig = new OfflinePunctuationConfig()
offlineConfig.model = config
this.handle = createOfflinePunctuation(offlineConfig)
}
offlinePunctuationAddPunct(text: string): string {
let result = offlinePunctuationAddPunct(this.handle, text)
return result
}
}
🤖 Prompt for AI Agents
In
@harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets
around lines 99 - 113, The constructor in class OfflinePunctuation uses a
misleading variable name `onlineConfig`; rename it to `offlineConfig` throughout
the constructor to match the class semantics: update the declaration
(OfflinePunctuationConfig), the assignment `offlineConfig.model = config`, and
the call to `createOfflinePunctuation(offlineConfig)` so all references inside
the constructor (in OfflinePunctuation) are consistently `offlineConfig`.

@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

本次 PR 主要是添加了为文本添加标点的功能,包括离线和在线的实现。整体实现清晰,但有几个地方可以改进:

  1. 测试代码中存在硬编码的路径和未使用的变量。
  2. 代码中存在一些命名不一致和具有误导性的变量名。
  3. 部分类的定义位置可以优化,以提高代码结构清晰度。
  4. 代码中遗留了一些被注释掉的“死代码”,建议清理。

具体的修改建议请见各文件的评论。

Comment on lines +8 to +9
const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;

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

模型目录路径 punctModelDir 和模型文件名 model.int8.onnx 是硬编码的字符串。建议将它们定义为常量,以提高代码的可维护性和可读性。例如,可以在文件的顶部或 struct 的静态成员中定义它们。

const punctModelDir = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12-int8';
modelConfig.ctTransformer = `${punctModelDir}/model.int8.onnx`;
let punctuation: OfflinePunctuation = new OfflinePunctuation(modelConfig)
let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you 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

变量 text 被赋值后从未被使用。这可能是未完成的逻辑或调试后遗留的代码。建议使用此结果(例如,打印日志或在UI上显示),或者如果不需要,则移除此赋值。为了方便调试,可以添加日志输出。

    let text = punctuation.offlinePunctuationAddPunct('这是一个测试你好吗How are you我很好thank you are you ok谢谢你');
    console.info(`[Punctuation] Result: ${text}`);

Comment on lines +44 to +48
export class OnlinePunctuationModelConfig {
public cnn_bilstm: string = '';
public bpe_vocab: string = '';
public provider: string = '';
}

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

在 OnlinePunctuationModelConfig 类中,属性 cnn_bilstm 和 bpe_vocab 使用了 snake_case 命名法。然而,在 TypeScript/ETS 中,更常见的约定是为类属性使用 camelCase,就像在 OfflinePunctuationModelConfig 中看到的 ctTransformer 一样。为了保持代码风格的一致性,建议将它们重命名为 cnnBilstm 和 bpeVocab。

export class OnlinePunctuationModelConfig {
  public cnnBilstm: string = '';
  public bpeVocab: string = '';
  public provider: string = '';
}

Comment on lines +99 to +113
export class OfflinePunctuation {
public handle: object;
// public config: OfflinePunctuationConfig

constructor(config: OfflinePunctuationModelConfig) {
let onlineConfig = new OfflinePunctuationConfig()
onlineConfig.model = config
this.handle = createOfflinePunctuation(onlineConfig)
}

offlinePunctuationAddPunct(text: string): string {
let result = offlinePunctuationAddPunct(this.handle, text)
return result
}
}

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

OfflinePunctuation 类的定义位于 StreamingAsr.ets 文件中。这会引起混淆,因为“离线”功能被放在了“流式”(通常是在线)ASR 的文件中。为了提高代码的组织性和清晰度,建议将这个类及其相关的配置类(OfflinePunctuationConfig, OfflinePunctuationModelConfig)移动到一个独立的文件中,例如 Punctuation.ets 或 OfflinePunctuation.ets。


export class OfflinePunctuation {
public handle: object;
// public config: OfflinePunctuationConfig

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

这行被注释掉的代码应该被移除,以保持代码的整洁性。

// public config: OfflinePunctuationConfig

constructor(config: OfflinePunctuationModelConfig) {
let onlineConfig = new OfflinePunctuationConfig()

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

变量 onlineConfig 的类型是 OfflinePunctuationConfig,但其命名却带有“online”。这个命名具有误导性,可能会导致混淆。建议将其重命名以准确反映其类型,例如 offlineConfig 或 config。

    let offlineConfig = new OfflinePunctuationConfig()

export class OnlineRecognizerConfig {
public featConfig: FeatureConfig = new FeatureConfig();
public modelConfig: OnlineModelConfig = new OnlineModelConfig();
// public punctuation: OfflinePunctuationModelConfig = new OfflinePunctuationModelConfig();

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

这行被注释掉的代码应该被移除,以保持代码的整洁性。如果这是一个待办事项,请使用 // TODO: 注释来明确说明。


export class OnlineRecognizer {
public handle: object;
// public punct: object;

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

这行被注释掉的代码应该被移除,以保持代码的整洁性。

Comment on lines +155 to +156
// let configp = new OfflinePunctuationModelConfig()
// this.punct = createOfflinePunctuation(configp)

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

这些被注释掉的代码行应该被移除,以保持代码的整洁。如果它们是为将来的功能保留的,请使用 // TODO: 注释来明确说明意图。

r.tokens = o.tokens;
r.json = jsonStr;

// r.text = offlinePunctuationAddPunct(this.punct, r.text)

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

这行被注释掉的代码应该被移除。如果它是一个占位符或待办事项,请使用 // TODO: 注释来提供上下文。

@csukuangfj

Copy link
Copy Markdown
Collaborator
  1. Please follow "*.ets" files inside
    https://github.com/k2-fsa/sherpa-onnx/tree/master/harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components
    to add two files
  • OnlinePunctuation.ets
  • OfflinePunctuation.ets
  1. Move the code you added in this PR from StreamingAsr.ets‎ and StreamingAsr.ets to OnlinePunctuation.ets and
    OfflinePunctuation.ets

  2. Update https://github.com/k2-fsa/sherpa-onnx/blob/master/harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets to export classes and structs from OnlinePunctuation.ets and OfflinePunctuation.ets

@jilinmo1 jilinmo1 closed this by deleting the head repository Jan 13, 2026
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.

2 participants