voice-changer/server/ModelSample.py
2023-05-17 22:18:28 +09:00

39 lines
954 B
Python

from dataclasses import dataclass
import json
from const import ModelType
@dataclass
class RVCModelSample:
id: str = ""
lang: str = ""
tag: str = ""
name: str = ""
modelUrl: str = ""
indexUrl: str = ""
featureUrl: str = ""
termsOfUseUrl: str = ""
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