normalize numbers to text as the g2p model doesn't handle this#358
normalize numbers to text as the g2p model doesn't handle this#358Alex-Wengg merged 1 commit intomainfrom
Conversation
|
Claude finished @smdesai's task —— View job Code Review Complete ✅I've reviewed this PR that adds number-to-text normalization for the TTS g2p model and provided detailed feedback. Todo List:
Review Summary: This is a well-implemented fix that addresses the core issue where numbers weren't being spoken by the TTS system. The Key highlights:
Recommendation: Approve - This solves the stated problem effectively and safely. |
There was a problem hiding this comment.
Code Review Summary
This PR addresses an important TTS issue where the g2p model doesn't handle numbers, causing them to be skipped in speech synthesis. The solution adds a spellOutWholeNumbers function that converts remaining numeric digits to their spoken form.
✅ Strengths
Excellent Processing Order: The number spelling is placed at step 10, after all other text normalization. This is crucial because:
- Numbers produced by earlier steps (ranges: "5-10" → "5 to 10", times: "12:30" → "12 30") also get converted
- Prevents edge cases like "five-10" instead of "five to ten"
- Ensures comprehensive number coverage
Smart Quote Addition: The smart quote normalization (normalizeSmartQuotes) is a nice bonus that improves text consistency.
Performance Optimized: Uses the shared spellOutFormatter instance from SSMLTypes.swift, avoiding expensive NumberFormatter creation.
Robust Pattern Matching: The regex \\b\\d+\\b correctly matches whole numbers with word boundaries, preventing partial matches in mixed alphanumeric strings.
🔍 Technical Details
Lines 217-240 - The spellOutWholeNumbers implementation:
- Correctly processes matches in reverse order to maintain string indices
- Handles potential parsing failures gracefully with guard statements
- Uses UTF16 count for NSRegularExpression compatibility
Lines 43-44 - Smart quote normalization covers the most common Unicode quote variants.
💭 Minor Considerations
Large Number Handling: The code relies on NumberFormatter.spellOut which handles very large numbers well (e.g., "1000000" → "one million"), but there's no explicit upper bound checking. This is likely fine for TTS use cases.
Edge Cases: The regex pattern handles standard integers but won't match numbers with leading zeros (e.g., "007"). This is probably the desired behavior for TTS.
🎯 Overall Assessment
This is a clean, well-thought-out implementation that solves the core problem effectively. The code follows the existing codebase patterns and integrates seamlessly with the preprocessing pipeline. The fix ensures that numbers like "5" become "five" so the TTS engine can properly synthesize them.
Recommendation: ✅ Approve - This addresses the stated issue comprehensively and follows good engineering practices.
PocketTTS Smoke Test ✅
Runtime: 0m20s Note: PocketTTS uses CoreML MLState (macOS 15) KV cache + Mimi streaming state. CI VM lacks physical GPU — audio quality may differ from Apple Silicon. |
|
|
||
| // 9. Handle phonetic replacement [Kokoro](/kˈOkəɹO/) | ||
| // 10. Spell out remaining whole numbers (5 → five, 10 → ten) | ||
| processed = spellOutWholeNumbers(processed) |
There was a problem hiding this comment.
🟡 Missing unit tests for new code violates Critical Rules in AGENTS.md
AGENTS.md under "Critical Rules" mandates: "Add unit tests when writing new code." This PR adds two new functions (normalizeSmartQuotes at line 130 and spellOutWholeNumbers at line 220) and a new preprocessing step (line 76), but no test file was modified or added. The git diff --name-only confirms only TtsTextPreprocessor.swift was changed. Tests exist for other preprocessor functionality in Tests/FluidAudioTests/TTS/SSMLTests.swift and Tests/FluidAudioTests/TTS/KokoroChunkerTests.swift, so there is an established test infrastructure to add to.
Prompt for agents
Add unit tests for the two new functions introduced in this PR. In Tests/FluidAudioTests/TTS/, add tests covering:
1. normalizeSmartQuotes: Verify that U+2018, U+2019, U+201C, U+201D are replaced with ASCII equivalents. Test mixed content, text with no smart quotes (passthrough), and text that is entirely smart quotes.
2. spellOutWholeNumbers: Verify basic cases like "5" → "five", "100" → "one hundred". Test that numbers embedded in words (e.g. "abc123def") are NOT replaced due to word boundaries. Test that the function handles text with no numbers (passthrough). Test interaction with prior pipeline steps (e.g. after range expansion "5 to 10" both numbers should be spelled out).
3. Integration: Test TtsTextPreprocessor.preprocess with input containing smart quotes and bare numbers to verify end-to-end behavior.
Was this helpful? React with 👍 or 👎 to provide feedback.
Parakeet EOU Benchmark Results ✅Status: Benchmark passed Performance Metrics
Streaming Metrics
Test runtime: 1m17s • 03/07/2026, 05:35 PM EST RTFx = Real-Time Factor (higher is better) • Processing includes: Model inference, audio preprocessing, state management, and file I/O |
Speaker Diarization Benchmark ResultsSpeaker Diarization PerformanceEvaluating "who spoke when" detection accuracy
Diarization Pipeline Timing BreakdownTime spent in each stage of speaker diarization
Speaker Diarization Research ComparisonResearch baselines typically achieve 18-30% DER on standard datasets
Note: RTFx shown above is from GitHub Actions runner. On Apple Silicon with ANE:
🎯 Speaker Diarization Test • AMI Corpus ES2004a • 1049.0s meeting audio • 68.5s diarization time • Test runtime: 3m 41s • 03/07/2026, 05:40 PM EST |
ASR Benchmark Results ✅Status: All benchmarks passed Parakeet v3 (multilingual)
Parakeet v2 (English-optimized)
Streaming (v3)
Streaming (v2)
Streaming tests use 5 files with 0.5s chunks to simulate real-time audio streaming 25 files per dataset • Test runtime: 6m33s • 03/07/2026, 05:41 PM EST RTFx = Real-Time Factor (higher is better) • Calculated as: Total audio duration ÷ Total processing time Expected RTFx Performance on Physical M1 Hardware:• M1 Mac: ~28x (clean), ~25x (other) Testing methodology follows HuggingFace Open ASR Leaderboard |
Sortformer High-Latency Benchmark ResultsES2004a Performance (30.4s latency config)
Sortformer High-Latency • ES2004a • Runtime: 2m 28s • 2026-03-07T22:41:28.734Z |
Qwen3-ASR int8 Smoke Test ✅
Runtime: 5m8s Note: CI VM lacks physical GPU — CoreML MLState (macOS 15) KV cache produces degraded results on virtualized runners. On Apple Silicon: ~1.3% WER / 2.5x RTFx. |
VAD Benchmark ResultsPerformance Comparison
Dataset Details
✅: Average F1-Score above 70% |
Offline VBx Pipeline ResultsSpeaker Diarization Performance (VBx Batch Mode)Optimal clustering with Hungarian algorithm for maximum accuracy
Offline VBx Pipeline Timing BreakdownTime spent in each stage of batch diarization
Speaker Diarization Research ComparisonOffline VBx achieves competitive accuracy with batch processing
Pipeline Details:
🎯 Offline VBx Test • AMI Corpus ES2004a • 1049.0s meeting audio • 302.7s processing • Test runtime: 4m 59s • 03/07/2026, 05:50 PM EST |
Why is this change needed?
The g2p model doesn't handle phoneme generation for numbers and as a result, numbers are not spoken. The solution is to speak out the numbers, e.g. "the range is 5 to 10" becomes "the range is five to ten".