From 78f7ae506d07443a0518eb00718819bd9c82f05d Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sat, 25 Jan 2025 10:56:27 -0500 Subject: [PATCH] Yet another attempt and handling charsets. --- Toby Doom Launcher.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Toby Doom Launcher.py b/Toby Doom Launcher.py index d002f57..b7831f5 100755 --- a/Toby Doom Launcher.py +++ b/Toby Doom Launcher.py @@ -248,26 +248,33 @@ class SpeechHandler: while True: try: line = process.stdout.readline() - # Keep gzdoom's existing functionality of lines being printed to the console. - print(line, end='') + if not isinstance(line, str): + line = line.decode('utf-8', errors='replace') + if not line: break - + + # Keep gzdoom's existing functionality of lines being printed to the console + print(line, end='', flush=True) + lineStr = line.strip() + if not lineStr: + continue # Wait for the initial separator before starting speech if not startSpeech: - if lineStr and all(c == '-' for c in lineStr): + if all(c == '-' for c in lineStr): startSpeech = True - continue + continue - processedLine = self.process_line(lineStr) - if processedLine: - self.speak(processedLine) + if startSpeech: + processedLine = self.process_line(lineStr) + if processedLine: + self.speak(processedLine) except Exception as e: print(f"Error processing game output: {e}", file=sys.stderr) - break + continue class MenuDialog(QDialog):