Fix load and save files

This commit is contained in:
WeberJulian 2022-05-30 18:52:41 +02:00
parent 7eceead0d7
commit 01115124a7
1 changed files with 12 additions and 7 deletions

View File

@ -12,20 +12,25 @@ from TTS.utils.audio import AudioProcessor
def load_file(path:str):
with fsspec.open(path, "rb") as f:
if path.endswith(".json"):
if path.endswith(".json"):
with fsspec.open(path, "r") as f:
return json.load(f)
elif path.endswith(".pth"):
elif path.endswith(".pth"):
with fsspec.open(path, "rb") as f:
return torch.load(f, map_location="cpu")
else:
raise ValueError("Unsupported file type")
def save_file(obj: Any, path:str):
with fsspec.open(path, "rb") as f:
if path.endswith(".json"):
if path.endswith(".json"):
with fsspec.open(path, "w") as f:
json.dump(obj, f, indent=4)
elif path.endswith(".pth"):
elif path.endswith(".pth"):
with fsspec.open(path, "wb") as f:
torch.save(obj, f)
else:
raise ValueError("Unsupported file type")
class BaseIDManager:
"""Base `ID` Manager class. Every new `ID` manager must inherit this.