Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “text simplification” feature for TTS, exposing it in the settings UI and persisting the preference via toJson/fromJson. The intent is to normalize chat text (punctuation/diacritics/box-drawing/braille/repeats/whitespace) and skip vocalization if the result becomes empty.
Changes:
- Add a persisted
isTextSimplificationEnabledflag with getter/setter onTtsModel. - Apply text-simplification logic inside
TtsModel.getVocalization(...)when enabled, including optional “skip if empty” behavior. - Add a new
SwitchListTilein TTS settings to toggle text simplification.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/screens/settings/tts.dart | Adds a settings toggle to enable/disable message text simplification for TTS. |
| lib/models/tts.dart | Introduces the model flag + persistence, and applies text simplification during vocalization generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
58a18cb to
402d934
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduce a text simplification feature for the TtsModel and expose it in the TTS settings. Adds a private flag, getter/setter (with notifyListeners), and persistence (toJson/fromJson). When enabled the message text is normalized by removing/replacing punctuation, diacritics, box-drawing/braille chars, collapsing repeated characters and whitespace; if the result is empty, vocalization is skipped. Also add a SwitchListTile in the settings UI to toggle the feature and log debug messages for simplified/skipped text. # Conflicts: # lib/models/tts.dart
402d934 to
111eae7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| text = text.replaceAll(_punctuation1, ' '); // replace punctuation with space except for apostrophes | ||
| text = text.replaceAll(_punctuation2, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation3, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation4, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation5, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_diacritics, ''); // remove diacritics | ||
| text = text.replaceAllMapped(_repeatedChars, (match) { | ||
| // replace repeated characters with a single instance | ||
| return match.group(1)!; | ||
| }); | ||
| text = text.replaceAll(_boxDrawing, ''); // remove box drawing characters | ||
| text = text.replaceAll(_braille, ''); // remove braille patterns | ||
|
|
||
| // Remove doubles spaces that may have been introduced and trim the text |
There was a problem hiding this comment.
The simplification path does 6+ full-string replaceAll passes plus replaceAllMapped, which can be unnecessarily expensive on longer messages and is harder to maintain as more rules are added. Consider collapsing the punctuation ranges into a single RegExp (or doing a single-pass rune/character filter) so the text is scanned fewer times.
| text = text.replaceAll(_punctuation1, ' '); // replace punctuation with space except for apostrophes | |
| text = text.replaceAll(_punctuation2, ' '); // replace punctuation with space | |
| text = text.replaceAll(_punctuation3, ' '); // replace punctuation with space | |
| text = text.replaceAll(_punctuation4, ' '); // replace punctuation with space | |
| text = text.replaceAll(_punctuation5, ' '); // replace punctuation with space | |
| text = text.replaceAll(_diacritics, ''); // remove diacritics | |
| text = text.replaceAllMapped(_repeatedChars, (match) { | |
| // replace repeated characters with a single instance | |
| return match.group(1)!; | |
| }); | |
| text = text.replaceAll(_boxDrawing, ''); // remove box drawing characters | |
| text = text.replaceAll(_braille, ''); // remove braille patterns | |
| // Remove doubles spaces that may have been introduced and trim the text | |
| // Combine punctuation, diacritics, box drawing, and braille patterns into a single pass. | |
| final _combinedSimplificationPattern = RegExp( | |
| '(${_punctuation1.pattern}|${_punctuation2.pattern}|${_punctuation3.pattern}|${_punctuation4.pattern}|${_punctuation5.pattern})' | |
| '|(${_diacritics.pattern})' | |
| '|(${_boxDrawing.pattern}|${_braille.pattern})'); | |
| text = text.replaceAllMapped(_combinedSimplificationPattern, (match) { | |
| // Group 1: punctuation -> replace with a space. | |
| if (match.group(1) != null) { | |
| return ' '; | |
| } | |
| // Group 2: diacritics -> remove. | |
| if (match.group(2) != null) { | |
| return ''; | |
| } | |
| // Group 3: box drawing or braille -> remove. | |
| return ''; | |
| }); | |
| text = text.replaceAllMapped(_repeatedChars, (match) { | |
| // replace repeated characters with a single instance | |
| return match.group(1)!; | |
| }); | |
| // Remove double spaces that may have been introduced and trim the text |
| if (_isTextSimplificationEnabled) { | ||
| text = text.replaceAll(_punctuation1, ' '); // replace punctuation with space except for apostrophes | ||
| text = text.replaceAll(_punctuation2, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation3, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation4, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation5, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_diacritics, ''); // remove diacritics | ||
| text = text.replaceAllMapped(_repeatedChars, (match) { |
There was a problem hiding this comment.
The diacritics stripping won’t work for most accented characters because the regex only removes combining marks (U+0300–U+036F). Typical input uses precomposed code points (e.g., “é” U+00E9), which won’t match unless the string is Unicode-normalized (NFD) first or a dedicated “remove diacritics” utility is used. Consider normalizing before applying _diacritics, or switching to a proven diacritic-stripping helper/package so the setting behaves as described.
| if (_isTextSimplificationEnabled) { | ||
| text = text.replaceAll(_punctuation1, ' '); // replace punctuation with space except for apostrophes | ||
| text = text.replaceAll(_punctuation2, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation3, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation4, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_punctuation5, ' '); // replace punctuation with space | ||
| text = text.replaceAll(_diacritics, ''); // remove diacritics | ||
| text = text.replaceAllMapped(_repeatedChars, (match) { | ||
| // replace repeated characters with a single instance | ||
| return match.group(1)!; | ||
| }); | ||
| text = text.replaceAll(_boxDrawing, ''); // remove box drawing characters | ||
| text = text.replaceAll(_braille, ''); // remove braille patterns | ||
|
|
||
| // Remove doubles spaces that may have been introduced and trim the text | ||
| text = text.replaceAll(_whitespace, ' ').trim(); | ||
| } |
There was a problem hiding this comment.
The PR description mentions logging debug messages when text is simplified or when vocalization is skipped due to simplification, but this change set doesn’t add any such logging (only the existing !v prefix logs remain). Either add the intended debug logging (ideally guarded by kDebugMode) or update the PR description to match the implemented behavior.
Introduce a text simplification feature for the TtsModel and expose it in the TTS settings. Adds a private flag, getter/setter (with notifyListeners), and persistence (toJson/fromJson). When enabled the message text is normalized by removing/replacing punctuation, diacritics, box-drawing/braille chars, collapsing repeated characters and whitespace; if the result is empty, vocalization is skipped. Also add a SwitchListTile in the settings UI to toggle the feature and log debug messages for simplified/skipped text.