voice-changer/server/data/ModelSample.py

62 lines
1.7 KiB
Python
Raw Normal View History

2023-06-16 10:49:55 +03:00
from dataclasses import dataclass, field
from typing import TypeAlias, Union, Any
from const import VoiceChangerType
@dataclass
class ModelSample:
id: str = ""
voiceChangerType: VoiceChangerType | None = None
@dataclass
class RVCModelSample(ModelSample):
2023-07-21 12:25:28 +03:00
id: str = ""
2023-06-16 10:49:55 +03:00
voiceChangerType: VoiceChangerType = "RVC"
lang: str = ""
tag: list[str] = field(default_factory=lambda: [])
name: str = ""
modelUrl: str = ""
indexUrl: str = ""
termsOfUseUrl: str = ""
icon: str = ""
credit: str = ""
description: str = ""
sampleRate: int = 48000
modelType: str = ""
f0: bool = True
2023-07-21 12:25:28 +03:00
@dataclass
class DiffusionSVCModelSample(ModelSample):
id: str = ""
voiceChangerType: VoiceChangerType = "Diffusion-SVC"
lang: str = ""
tag: list[str] = field(default_factory=lambda: [])
name: str = ""
modelUrl: str = ""
termsOfUseUrl: str = ""
icon: str = ""
credit: str = ""
description: str = ""
sampleRate: int = 48000
modelType: str = ""
f0: bool = True
numOfDiffLayers: int = 20
numOfNativeLayers: int = 3
maxKStep: int = 50
ModelSamples: TypeAlias = Union[ModelSample, RVCModelSample, DiffusionSVCModelSample]
2023-06-16 10:49:55 +03:00
def generateModelSample(params: Any) -> ModelSamples:
if params["voiceChangerType"] == "RVC":
2023-07-21 12:25:28 +03:00
return RVCModelSample(**{k: v for k, v in params.items() if k in RVCModelSample.__annotations__})
elif params["voiceChangerType"] == "Diffusion-SVC":
return DiffusionSVCModelSample(**{k: v for k, v in params.items() if k in DiffusionSVCModelSample.__annotations__})
2023-06-16 10:49:55 +03:00
else:
return ModelSample(**{k: v for k, v in params.items() if k in ModelSample.__annotations__})