Disable text to speech if self-voice is selected. This was harder than I thought it would be. Please report bugs if found.

This commit is contained in:
Storm Dragon 2025-01-22 02:58:55 -05:00
parent 02b598e987
commit a71bb0e608

View File

@ -169,18 +169,40 @@ class SpeechHandler:
(r' ?\*+ ?', r'')
]
def __init__(self):
def __init__(self, config_file: Path):
"""Initialize the speech handler"""
self.platform = platform.system()
self.use_tts = self._check_narration_type(config_file)
# Compile all regex patterns once at initialization
self.filterPatterns = [re.compile(pattern) for pattern in self.FILTER_PATTERNS]
self.textReplacements = [(re.compile(pattern), repl)
for pattern, repl in self.TEXT_REPLACEMENTS]
def set_tts_state(self, enabled: bool) -> None:
"""Update voicing style"""
self.use_tts = enabled
def _check_narration_type(self, config_file: Path) -> bool:
"""Check if TTS should be used, returns False for self-voiced"""
try:
if not config_file.exists():
return False
with open(config_file, 'r') as f:
for line in f:
line = line.strip()
if line.startswith('Toby_NarrationOutputType='):
value = int(line.split('=')[1].strip())
return value == 2
return False
except Exception as e:
print(f"Error reading config: {e}", file=sys.stderr)
return False
def speak(self, text: str) -> None:
"""Speak text using available speech method"""
if not text:
if not text or not self.use_tts:
return
if speechProvider == "speechd":
@ -803,7 +825,7 @@ class DoomLauncher(QMainWindow):
self.configFile = Path(os.getenv('XDG_CONFIG_HOME', Path.home() / '.config')) / 'gzdoom/gzdoom.ini'
self.tobyVersion = TOBY_VERSION
self.speechHandler = SpeechHandler()
self.speechHandler = SpeechHandler(self.configFile)
self.iwadSelector = IWADSelector() # Add IWAD selector
self.init_launcher_ui()
@ -972,6 +994,9 @@ class DoomLauncher(QMainWindow):
self.narrationCombo.setCurrentText(
"Self-voiced" if current == 0 else "Text to Speech"
)
else:
# Update speech handler state directly
self.speechHandler.set_tts_state(value == 2)
def populate_game_list(self):
"""Populate the game selection combo box"""