fix(language-detector): changed tinyld for google Language Detector#4544
fix(language-detector): changed tinyld for google Language Detector#4544AARP41298 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughReplaces the tinyld-based synchronous language detection in the synced-lyrics romanization flow with an async MediaPipe Tasks Text detector. Adds a new language-detector module, a TypeScript declaration for .tflite?url assets, updates package.json dependencies, and adjusts romanize to await the new detector. ChangesLanguage Detection Replacement
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Utils as romanize()
participant Detector as detectLanguage()
participant MediaPipe as LanguageDetector
participant CDN as CDN WASM/model
Utils->>Detector: detectLanguage(line)
Detector->>MediaPipe: lazy init (if needed)
MediaPipe->>CDN: fetch WASM fileset + tflite model
CDN-->>MediaPipe: assets loaded
Detector->>MediaPipe: detect(text)
MediaPipe-->>Detector: top language result
Detector-->>Utils: normalized language code or undefined
Related issues: Suggested labels: dependencies, plugin: synced-lyrics, enhancement Suggested reviewers: semvis123 🐰 A rabbit swapped one guesser for a smarter friend, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/plugins/synced-lyrics/language-detector.ts (1)
9-20: 🩺 Stability & Availability | 🔵 Trivial | 🏗️ Heavy liftCDN-hosted WASM fetch with a likely-permanent cached failure and silent error swallowing.
The WASM fileset is fetched at runtime from an external CDN (Line 10) inside a
lazy-varsingleton (Lines 12-20). If that first fetch fails (offline, blocked CDN, transient network issue), the memoized lazy value is very likely a rejected promise, so all subsequentdetectLanguagecalls for the rest of the session immediately hit the barecatch {}(Lines 35-37) and silently fall back to the old heuristic-based detection — reintroducing the exact Chinese-vs-Japanese misdetection this PR is meant to fix, with no logging to diagnose it.Consider: bundling the WASM runtime alongside the model (consistent with how the model is already bundled locally) to remove the network dependency, and/or resetting the lazy value on failure so a later call can retry, and/or logging the failure for observability.
Also applies to: 35-37
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/plugins/synced-lyrics/language-detector.ts` around lines 9 - 20, The runtime WASM load in language-detector.ts is relying on a CDN-backed lazy singleton that can fail once and then stay rejected for the rest of the session, while detectLanguage silently swallows the error. Update the LanguageDetector setup around lazyVar.lazy and detectLanguage so the WASM/fileset is bundled or otherwise not dependent on the external CDN, and ensure a failed initialization can be retried or the cached failure is cleared. Also replace the bare catch in detectLanguage with logging so failures are observable instead of silently falling back.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/plugins/synced-lyrics/language-detector.ts`:
- Around line 9-20: The runtime WASM load in language-detector.ts is relying on
a CDN-backed lazy singleton that can fail once and then stay rejected for the
rest of the session, while detectLanguage silently swallows the error. Update
the LanguageDetector setup around lazyVar.lazy and detectLanguage so the
WASM/fileset is bundled or otherwise not dependent on the external CDN, and
ensure a failed initialization can be retried or the cached failure is cleared.
Also replace the bare catch in detectLanguage with logging so failures are
observable instead of silently falling back.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e4ef0fbf-95dc-4fa9-a4c9-41f82d6a36f5
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
package.jsonsrc/pear-desktop.tssrc/plugins/synced-lyrics/language-detector.tssrc/plugins/synced-lyrics/language_detector.tflitesrc/plugins/synced-lyrics/renderer/utils.tsx
|
Radwimps - Sparkle 2:47 1000年周期を 一日で息しよう //100 JP |
Fix #4529
Vibe coded
Summary by CodeRabbit
New Features
Bug Fixes