voice-changer/server/ModelSample.py

44 lines
1.1 KiB
Python
Raw Normal View History

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