From f52a5ae3c2fa03a3bec21818039b51a14a4bbdd0 Mon Sep 17 00:00:00 2001 From: Ava Date: Mon, 13 Jan 2025 23:12:38 +1100 Subject: [PATCH] specify encoding to ensure Python reads file as UTF-8 executing `python whisper_fastapi_online_server.py --host 0.0.0.0 --port 8000` resulted in error on my setup for me: ``` whisper_streaming_web\whisper_fastapi_online_server.py, line 47, in html = f.read() ^^^^^^^^ File "C:\Python312\Lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1818: character maps to ``` On Windows, Python defaults to the `cp1252` encoding, which may not match the encoding of the file being read. Files containing special characters, non-ASCII text, or saved with UTF-8 encoding can trigger this error when read without specifying the correct encoding. --- whisper_fastapi_online_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whisper_fastapi_online_server.py b/whisper_fastapi_online_server.py index 0813496..17d6bcf 100644 --- a/whisper_fastapi_online_server.py +++ b/whisper_fastapi_online_server.py @@ -43,7 +43,7 @@ args = parser.parse_args() asr, tokenizer = backend_factory(args) # Load demo HTML for the root endpoint -with open("src/live_transcription.html", "r") as f: +with open("src/live_transcription.html", "r", encoding="utf-8") as f: html = f.read()