Back to trying to fix non-English encodings.
This commit is contained in:
parent
a71bb0e608
commit
c3c9da9403
@ -249,14 +249,23 @@ class SpeechHandler:
|
||||
# Read directly from stdout, no need for buffer attribute
|
||||
for line in process.stdout:
|
||||
try:
|
||||
# Handle encoding by trying utf-8 first, then fallback to latin1
|
||||
# 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('utf-8').strip()
|
||||
lineStr = line.decode(encoding).strip()
|
||||
else:
|
||||
lineStr = line.strip()
|
||||
break # Successfully decoded
|
||||
except UnicodeDecodeError:
|
||||
lineStr = line.decode('latin1').strip()
|
||||
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)
|
||||
@ -269,7 +278,10 @@ class SpeechHandler:
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user