mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-08-29 10:09:32 +02:00
16 lines
602 B
Python
16 lines
602 B
Python
def read_text(path, errors="strict", newline=None):
|
|
last_error = None
|
|
for encoding in (None, "utf8", "gbk"):
|
|
try:
|
|
kwargs = {"errors": "strict", "newline": newline}
|
|
if encoding is not None:
|
|
kwargs["encoding"] = encoding
|
|
with open(path, "r", **kwargs) as file:
|
|
return file.read()
|
|
except UnicodeDecodeError as error:
|
|
last_error = error
|
|
if errors != "strict":
|
|
with open(path, "r", encoding="gbk", errors=errors, newline=newline) as file:
|
|
return file.read()
|
|
raise last_error
|