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
|
# Read directly from stdout, no need for buffer attribute
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
try:
|
try:
|
||||||
# Handle encoding by trying utf-8 first, then fallback to latin1
|
# Try multiple encodings in order
|
||||||
try:
|
encodings = ['utf-8', 'gbk', 'big5', 'latin1']
|
||||||
if isinstance(line, bytes):
|
lineStr = None
|
||||||
lineStr = line.decode('utf-8').strip()
|
|
||||||
else:
|
for encoding in encodings:
|
||||||
lineStr = line.strip()
|
try:
|
||||||
except UnicodeDecodeError:
|
if isinstance(line, bytes):
|
||||||
lineStr = line.decode('latin1').strip()
|
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
|
# Keep gzdoom's existing functionality of lines being printed to the console
|
||||||
print(lineStr)
|
print(lineStr)
|
||||||
@ -269,7 +278,10 @@ class SpeechHandler:
|
|||||||
|
|
||||||
processedLine = self.process_line(lineStr)
|
processedLine = self.process_line(lineStr)
|
||||||
if processedLine:
|
if processedLine:
|
||||||
self.speak(processedLine)
|
try:
|
||||||
|
self.speak(processedLine)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error speaking line: {e}", file=sys.stderr)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing line: {e}", file=sys.stderr)
|
print(f"Error processing line: {e}", file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user