From f0dd73a4197e2b12ec5a28dc26d1512ea7d93846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=8E=A9=E5=B9=BB=E7=81=B5qwq?= <94176676+HuanLinOTO@users.noreply.github.com> Date: Sun, 9 Jun 2024 00:05:12 +0800 Subject: [PATCH] feat: fallback to system encoding when fail to read file with utf-8 --- infer/lib/train/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/infer/lib/train/utils.py b/infer/lib/train/utils.py index e7bb783..765c54c 100644 --- a/infer/lib/train/utils.py +++ b/infer/lib/train/utils.py @@ -278,8 +278,13 @@ def load_wav_to_torch(full_path): def load_filepaths_and_text(filename, split="|"): - with open(filename, encoding="utf-8") as f: - filepaths_and_text = [line.strip().split(split) for line in f] + try: + with open(filename, encoding="utf-8") as f: + filepaths_and_text = [line.strip().split(split) for line in f] + except UnicodeDecodeError: + with open(filename) as f: + filepaths_and_text = [line.strip().split(split) for line in f] + return filepaths_and_text