Repository navigation
Refactor Go API examples to use sherpa_onnx.ReadWave() - #3415
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughEight Go example programs replace local WAV-reading helpers with a single call to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello, 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 refactors the Go API examples by replacing the custom WAV file reading implementations with the dedicated Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors several Go API examples by replacing custom wave file reading logic with a new sherpa.ReadWave function from the sherpa-onnx-go library. This change simplifies the code by removing redundant imports and functions, and introduces error handling for wave file reading. Feedback suggests improving readability by storing flag.Arg(0) in a variable and ensuring consistent camelCase naming for variables like wav_filename to align with Go conventions.
| log.Println("Reading", flag.Arg(0)) | ||
|
|
||
| samples, sampleRate := readWave(flag.Arg(0)) | ||
| wave := sherpa.ReadWave(flag.Arg(0)) | ||
| if wave == nil { | ||
| log.Fatalf("Failed to read %v", flag.Arg(0)) | ||
| } |
There was a problem hiding this comment.
To improve readability and avoid calling flag.Arg(0) multiple times, it's a good practice to store its result in a variable.
| log.Println("Reading", flag.Arg(0)) | |
| samples, sampleRate := readWave(flag.Arg(0)) | |
| wave := sherpa.ReadWave(flag.Arg(0)) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", flag.Arg(0)) | |
| } | |
| waveFilename := flag.Arg(0) | |
| log.Println("Reading", waveFilename) | |
| wave := sherpa.ReadWave(waveFilename) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", waveFilename) | |
| } |
| log.Println("Reading", flag.Arg(0)) | ||
|
|
||
| samples, sampleRate := readWave(flag.Arg(0)) | ||
| wave := sherpa.ReadWave(flag.Arg(0)) | ||
| if wave == nil { | ||
| log.Fatalf("Failed to read %v", flag.Arg(0)) | ||
| } |
There was a problem hiding this comment.
To improve readability and avoid calling flag.Arg(0) multiple times, it's a good practice to store its result in a variable.
| log.Println("Reading", flag.Arg(0)) | |
| samples, sampleRate := readWave(flag.Arg(0)) | |
| wave := sherpa.ReadWave(flag.Arg(0)) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", flag.Arg(0)) | |
| } | |
| waveFilename := flag.Arg(0) | |
| log.Println("Reading", waveFilename) | |
| wave := sherpa.ReadWave(waveFilename) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", waveFilename) | |
| } |
| wav_filename := "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/8k.wav" | ||
|
|
||
| samples, sampleRate := readWave(wav_filename) | ||
| wave := sherpa.ReadWave(wav_filename) | ||
| if wave == nil { | ||
| log.Fatalf("Failed to read %v", wav_filename) | ||
| } |
There was a problem hiding this comment.
For consistency with Go conventions and other examples in this repository, it's better to use camelCase for variable names. Please rename wav_filename to waveFilename.
| wav_filename := "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/8k.wav" | |
| samples, sampleRate := readWave(wav_filename) | |
| wave := sherpa.ReadWave(wav_filename) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", wav_filename) | |
| } | |
| waveFilename := "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/8k.wav" | |
| wave := sherpa.ReadWave(waveFilename) | |
| if wave == nil { | |
| log.Fatalf("Failed to read %v", waveFilename) | |
| } |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
go-api-examples/streaming-hlg-decoding/main.go (1)
26-26: Minor: Pre-existing naming inconsistency.The variable
wav_filenameuses snake_case while other example files use camelCase (waveFilename). This is a pre-existing inconsistency, not introduced by this PR, but could be addressed for consistency if desired.♻️ Optional: Align variable naming with other examples
- wav_filename := "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/8k.wav" + waveFilename := "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/8k.wav" - wave := sherpa.ReadWave(wav_filename) + wave := sherpa.ReadWave(waveFilename) if wave == nil { - log.Fatalf("Failed to read %v", wav_filename) + log.Fatalf("Failed to read %v", waveFilename) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@go-api-examples/streaming-hlg-decoding/main.go` at line 26, Rename the snake_case variable wav_filename to camelCase waveFilename across the file to match other examples; update all references (declaration and uses) where wav_filename appears (e.g., in main or any helper functions) so the identifier is consistently waveFilename and build/imports remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@go-api-examples/streaming-hlg-decoding/main.go`:
- Line 26: Rename the snake_case variable wav_filename to camelCase waveFilename
across the file to match other examples; update all references (declaration and
uses) where wav_filename appears (e.g., in main or any helper functions) so the
identifier is consistently waveFilename and build/imports remain unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6d789010-87c9-43fa-8d4e-88c8c2db80b6
📒 Files selected for processing (8)
go-api-examples/non-streaming-canary-decode-files/main.gogo-api-examples/non-streaming-decode-files/main.gogo-api-examples/non-streaming-funasr-nano-decode-files/main.gogo-api-examples/non-streaming-medasr-ctc-decode-files/main.gogo-api-examples/non-streaming-moonshine-v2-decode-files/main.gogo-api-examples/non-streaming-omnilingual-asr-ctc-decode-files/main.gogo-api-examples/streaming-decode-files/main.gogo-api-examples/streaming-hlg-decoding/main.go
Summary by CodeRabbit