Skip to content

Commit 258eddb

Browse files
committed
Enable underscore replacement by default
Change the default for _isUnderscoreReplacementEnabled in TtsModel from false to true so underscore replacement is enabled by default in TTS behavior. Add option to replace underscores in author names for TTS Introduces a new setting to replace underscores with spaces in author names when generating TTS prelude. Adds a toggle in the TTS settings screen and persists the setting in the TtsModel. # Conflicts: # lib/models/tts.dart # lib/screens/settings/tts.dart
1 parent b5a2485 commit 258eddb

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/models/tts.dart

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TtsModel extends ChangeNotifier {
6565
var _isBotMuted = false;
6666
var _isEmoteMuted = false;
6767
var _isPreludeMuted = false;
68+
var _isUnderscoreReplacementEnabled = true;
6869
var _isTtsCommandEncouraged = false;
6970
var _speed = Platform.isAndroid ? 0.8 : 0.395;
7071
var _pitch = 1.0;
@@ -185,8 +186,16 @@ class TtsModel extends ChangeNotifier {
185186
if (text.trim().isEmpty) {
186187
return "";
187188
}
188-
189-
final author = model.author.displayName ?? model.author.login;
189+
var author = model.author.displayName ?? model.author.login;
190+
if (_isUnderscoreReplacementEnabled) {
191+
author = author
192+
.replaceAll("_", " ")
193+
.replaceAll(RegExp(r'\s+'), ' ')
194+
.trim();
195+
}
196+
if (!includeAuthorPrelude || isPreludeMuted) {
197+
return text;
198+
}
190199
return model.isAction
191200
? l10n.actionMessage(author, text)
192201
: l10n.saidMessage(author, text);
@@ -385,6 +394,15 @@ class TtsModel extends ChangeNotifier {
385394
notifyListeners();
386395
}
387396

397+
bool get isUnderscoreReplacementEnabled {
398+
return _isUnderscoreReplacementEnabled;
399+
}
400+
401+
set isUnderscoreReplacementEnabled(bool value) {
402+
_isUnderscoreReplacementEnabled = value;
403+
notifyListeners();
404+
}
405+
388406
bool get isCloudTtsEnabled {
389407
return _isCloudTtsEnabled;
390408
}
@@ -582,6 +600,9 @@ class TtsModel extends ChangeNotifier {
582600
if (json['isPreludeMuted'] != null) {
583601
_isPreludeMuted = json['isPreludeMuted'];
584602
}
603+
if (json['isUnderscoreReplacementEnabled'] != null) {
604+
_isUnderscoreReplacementEnabled = json['isUnderscoreReplacementEnabled'];
605+
}
585606
if (json['isRandomVoiceEnabled'] != null) {
586607
_isRandomVoiceEnabled = json['isRandomVoiceEnabled'];
587608
}
@@ -608,6 +629,7 @@ class TtsModel extends ChangeNotifier {
608629
"isEmoteMuted": isEmoteMuted,
609630
"isTextSimplificationEnabled": isTextSimplificationEnabled,
610631
"isPreludeMuted": isPreludeMuted,
632+
"isUnderscoreReplacementEnabled": isUnderscoreReplacementEnabled,
611633
"isTtsCommandEncouraged": isTtsCommandEncouraged,
612634
"isRandomVoiceEnabled": isRandomVoiceEnabled,
613635
"language": language.languageCode,

lib/screens/settings/tts.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ class TextToSpeechScreen extends StatelessWidget {
264264
model.isPreludeMuted = value;
265265
},
266266
),
267+
SwitchListTile.adaptive(
268+
title: const Text("Replace underscores with spaces in viewer names"),
269+
value: model.isUnderscoreReplacementEnabled,
270+
onChanged: (value) {
271+
model.isUnderscoreReplacementEnabled = value;
272+
},
273+
),
267274
SwitchListTile.adaptive(
268275
title: const Text("Simplify messages"),
269276
subtitle: const Text("Simplify punctuation, symbols, and whitespace (including muting repetitive punctuation and unsupported characters)"),

0 commit comments

Comments
 (0)