Skip to content

Commit 09285d5

Browse files
authored
perf: improve codec handling in load_filepaths_and_text function in infer.lib.train.utils (#44)
1 parent 26d17cd commit 09285d5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

infer/lib/train/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77

8+
import codecs
89
import numpy as np
910
import torch
1011
from scipy.io.wavfile import read
@@ -251,13 +252,11 @@ def load_wav_to_torch(full_path):
251252

252253
def load_filepaths_and_text(filename, split="|"):
253254
try:
254-
with open(filename, encoding="utf-8") as f:
255-
filepaths_and_text = [line.strip().split(split) for line in f]
256-
except UnicodeDecodeError:
257-
with open(filename) as f:
258-
filepaths_and_text = [line.strip().split(split) for line in f]
255+
return [line.strip().split(split) for line in codecs.open(filename, encoding="utf-8")]
256+
except UnicodeDecodeError as e:
257+
logger.error("Error loading file %s: %s", filename, e)
259258

260-
return filepaths_and_text
259+
return []
261260

262261

263262
def get_hparams(init=True):

0 commit comments

Comments
 (0)