voice-changer/server/ModelSample.py

39 lines
954 B
Python
Raw Normal View History

2023-05-16 04:38:23 +03:00
from dataclasses import dataclass
import json
from const import ModelType
@dataclass
class RVCModelSample:
id: str = ""
2023-05-17 01:20:43 +03:00
lang: str = ""
tag: str = ""
2023-05-16 04:38:23 +03:00
name: str = ""
modelUrl: str = ""
indexUrl: str = ""
featureUrl: str = ""
2023-05-17 16:18:28 +03:00
termsOfUseUrl: str = ""
2023-05-16 04:38:23 +03:00
credit: str = ""
description: str = ""
def getModelSamples(jsonPath: str, modelType: ModelType):
try:
with open(jsonPath, "r", encoding="utf-8") as f:
jsonDict = json.load(f)
modelList = jsonDict[modelType]
if modelType == "RVC":
samples: list[RVCModelSample] = []
for s in modelList:
modelSample = RVCModelSample(**s)
samples.append(modelSample)
return samples
else:
raise RuntimeError(f"Unknown model type {modelType}")
except Exception as e:
print("[Voice Changer] loading sample info error:", e)
return None