diff --git a/Toby Doom Launcher.py b/Toby Doom Launcher.py index 78348c9..d002f57 100755 --- a/Toby Doom Launcher.py +++ b/Toby Doom Launcher.py @@ -244,51 +244,30 @@ class SpeechHandler: def speak_thread(self, process: subprocess.Popen): """Thread to handle speech processing""" startSpeech = False # Don't start speaking until after initial output - - try: - # Read directly from stdout, no need for buffer attribute - for line in process.stdout: - try: - # Try multiple encodings in order - encodings = ['utf-8', 'gbk', 'big5', 'latin1'] - lineStr = None - - for encoding in encodings: - try: - if isinstance(line, bytes): - lineStr = line.decode(encoding).strip() - else: - lineStr = line.strip() - break # Successfully decoded - except UnicodeDecodeError: - continue - - if lineStr is None: - print(f"Failed to decode line with any encoding", file=sys.stderr) - continue - - # Keep gzdoom's existing functionality of lines being printed to the console - print(lineStr) - - # Wait for the initial separator before starting speech - if not startSpeech: - if lineStr and all(c == '-' for c in lineStr): - startSpeech = True - continue - - processedLine = self.process_line(lineStr) - if processedLine: - try: - self.speak(processedLine) - except Exception as e: - print(f"Error speaking line: {e}", file=sys.stderr) - - except Exception as e: - print(f"Error processing line: {e}", file=sys.stderr) - continue # Skip this line and continue with the next - - except Exception as e: - print(f"Error in speech thread: {e}", file=sys.stderr) + + while True: + try: + line = process.stdout.readline() + # Keep gzdoom's existing functionality of lines being printed to the console. + print(line, end='') + if not line: + break + + lineStr = line.strip() + + # Wait for the initial separator before starting speech + if not startSpeech: + if lineStr and all(c == '-' for c in lineStr): + startSpeech = True + continue + + 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 class MenuDialog(QDialog):