Skip to content

Commit

Permalink
fix: specify encoding to utf-8 in read_text() and write_text() (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
34j committed Apr 30, 2023
1 parent ed3240a commit e947336
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/so_vits_svc_fork/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, hps: HParams, is_validation: bool = False):
for x in Path(
hps.data.validation_files if is_validation else hps.data.training_files
)
.read_text()
.read_text("utf-8")
.splitlines()
]
self.hps = hps
Expand Down
6 changes: 4 additions & 2 deletions src/so_vits_svc_fork/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def play_audio(path: Path | str):


def load_presets() -> dict:
defaults = json.loads(GUI_DEFAULT_PRESETS_PATH.read_text())
defaults = json.loads(GUI_DEFAULT_PRESETS_PATH.read_text("utf-8"))
users = (
json.loads(GUI_PRESETS_PATH.read_text()) if GUI_PRESETS_PATH.exists() else {}
json.loads(GUI_PRESETS_PATH.read_text("utf-8"))
if GUI_PRESETS_PATH.exists()
else {}
)
# prioriy: defaults > users
# order: defaults -> users
Expand Down
28 changes: 12 additions & 16 deletions src/so_vits_svc_fork/preprocessing/preprocess_flist_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,28 @@ def preprocess_config(

LOG.info(f"Writing {train_list_path}")
train_list_path.parent.mkdir(parents=True, exist_ok=True)
with train_list_path.open("w", encoding="utf-8") as f:
for fname in train:
wavpath = fname.as_posix()
f.write(wavpath + "\n")
train_list_path.write_text(
"\n".join([x.as_posix() for x in train]), encoding="utf-8"
)

LOG.info(f"Writing {val_list_path}")
val_list_path.parent.mkdir(parents=True, exist_ok=True)
with val_list_path.open("w", encoding="utf-8") as f:
for fname in val:
wavpath = fname.as_posix()
f.write(wavpath + "\n")
val_list_path.write_text("\n".join([x.as_posix() for x in val]), encoding="utf-8")

LOG.info(f"Writing {test_list_path}")
test_list_path.parent.mkdir(parents=True, exist_ok=True)
with test_list_path.open("w", encoding="utf-8") as f:
for fname in test:
wavpath = fname.as_posix()
f.write(wavpath + "\n")
test_list_path.write_text("\n".join([x.as_posix() for x in test]), encoding="utf-8")

config = deepcopy(
json.loads(
(
CONFIG_TEMPLATE_DIR / f"{config_name}.json"
if not config_name.endswith(".json")
else config_name
).read_text()
CONFIG_TEMPLATE_DIR
/ (
config_name
if config_name.endswith(".json")
else config_name + ".json"
)
).read_text(encoding="utf-8")
)
)
config["spk"] = spk_dict
Expand Down
2 changes: 1 addition & 1 deletion src/so_vits_svc_fork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def get_backup_hparams(


def get_hparams(config_path: Path | str) -> HParams:
config = json.loads(Path(config_path).read_text())
config = json.loads(Path(config_path).read_text("utf-8"))
hparams = HParams(**config)
return hparams

Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_train(self):
from so_vits_svc_fork.train import train

config_path = Path("tests/logs/44k/config.json")
config_json = json.loads(config_path.read_text())
config_json = json.loads(config_path.read_text("utf-8"))
config_json["train"]["epochs"] = 1
config_path.write_text(json.dumps(config_json))
config_path.write_text(json.dumps(config_json), "utf-8")
train(config_path, "tests/logs/44k")

0 comments on commit e947336

Please sign in to comment.