Skip to content

Add text simplification option for TTS#4

Merged
LeMyst merged 1 commit intomainfrom
feat/remove-punctuation-in-messages
Feb 28, 2026
Merged

Add text simplification option for TTS#4
LeMyst merged 1 commit intomainfrom
feat/remove-punctuation-in-messages

Conversation

@LeMyst
Copy link
Owner

@LeMyst LeMyst commented Feb 22, 2026

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 isTextSimplificationEnabled flag with getter/setter on TtsModel.
  • Apply text-simplification logic inside TtsModel.getVocalization(...) when enabled, including optional “skip if empty” behavior.
  • Add a new SwitchListTile in 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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
@LeMyst LeMyst force-pushed the feat/remove-punctuation-in-messages branch from 402d934 to 111eae7 Compare February 28, 2026 18:20
@LeMyst LeMyst requested a review from Copilot February 28, 2026 18:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +164 to +177
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
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +163 to +170
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) {
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +163 to 179
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();
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@LeMyst LeMyst merged commit 820c5f5 into main Feb 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants