voice-changer/server/const.py

172 lines
6.4 KiB
Python
Raw Normal View History

2023-05-02 06:11:00 +03:00
from enum import Enum
2023-01-28 08:01:23 +03:00
import os
import sys
2023-01-15 23:22:27 +03:00
import tempfile
from typing import Literal, TypeAlias
2023-06-16 10:49:55 +03:00
VoiceChangerType: TypeAlias = Literal[
"MMVCv13",
"MMVCv15",
"so-vits-svc-40",
"DDSP-SVC",
"RVC",
]
2023-04-28 00:39:51 +03:00
ModelType: TypeAlias = Literal[
"MMVCv15",
"MMVCv13",
"so-vits-svc-40v2",
"so-vits-svc-40",
"so-vits-svc-40_c",
"DDSP-SVC",
"RVC",
]
2023-01-08 11:58:27 +03:00
2023-01-15 23:31:49 +03:00
tmpdir = tempfile.TemporaryDirectory()
2023-01-28 08:01:23 +03:00
SSL_KEY_DIR = os.path.join(tmpdir.name, "keys") if hasattr(sys, "_MEIPASS") else "keys"
2023-01-15 23:31:49 +03:00
MODEL_DIR = os.path.join(tmpdir.name, "logs") if hasattr(sys, "_MEIPASS") else "logs"
2023-06-16 10:49:55 +03:00
UPLOAD_DIR = os.path.join(tmpdir.name, "upload_dir") if hasattr(sys, "_MEIPASS") else "upload_dir"
NATIVE_CLIENT_FILE_WIN = os.path.join(sys._MEIPASS, "voice-changer-native-client.exe") if hasattr(sys, "_MEIPASS") else "voice-changer-native-client" # type: ignore
2023-04-28 00:39:51 +03:00
NATIVE_CLIENT_FILE_MAC = (
os.path.join(
sys._MEIPASS, # type: ignore
"voice-changer-native-client.app",
"Contents",
"MacOS",
"voice-changer-native-client",
)
if hasattr(sys, "_MEIPASS")
else "voice-changer-native-client"
)
2023-01-28 08:01:23 +03:00
2023-06-16 10:49:55 +03:00
HUBERT_ONNX_MODEL_PATH = os.path.join(sys._MEIPASS, "model_hubert/hubert_simple.onnx") if hasattr(sys, "_MEIPASS") else "model_hubert/hubert_simple.onnx" # type: ignore
2023-03-30 18:53:00 +03:00
2023-01-28 08:01:23 +03:00
2023-06-16 10:49:55 +03:00
TMP_DIR = os.path.join(tmpdir.name, "tmp_dir") if hasattr(sys, "_MEIPASS") else "tmp_dir"
2023-02-14 23:02:51 +03:00
os.makedirs(TMP_DIR, exist_ok=True)
2023-03-08 03:48:50 +03:00
def getFrontendPath():
2023-06-16 10:49:55 +03:00
frontend_path = os.path.join(sys._MEIPASS, "dist") if hasattr(sys, "_MEIPASS") else "../client/demo/dist"
2023-03-08 03:48:50 +03:00
return frontend_path
2023-05-02 06:11:00 +03:00
2023-05-02 14:57:12 +03:00
# "hubert_base", "contentvec", "distilhubert"
2023-05-02 06:11:00 +03:00
class EnumEmbedderTypes(Enum):
2023-05-02 14:57:12 +03:00
hubert = "hubert_base"
2023-05-02 06:11:00 +03:00
contentvec = "contentvec"
2023-05-02 14:57:12 +03:00
hubert_jp = "hubert-base-japanese"
class EnumInferenceTypes(Enum):
pyTorchRVC = "pyTorchRVC"
pyTorchRVCNono = "pyTorchRVCNono"
2023-05-20 09:54:00 +03:00
pyTorchRVCv2 = "pyTorchRVCv2"
pyTorchRVCv2Nono = "pyTorchRVCv2Nono"
2023-05-02 14:57:12 +03:00
pyTorchWebUI = "pyTorchWebUI"
pyTorchWebUINono = "pyTorchWebUINono"
onnxRVC = "onnxRVC"
onnxRVCNono = "onnxRVCNono"
2023-05-02 16:29:28 +03:00
class EnumPitchExtractorTypes(Enum):
harvest = "harvest"
dio = "dio"
2023-05-20 10:33:17 +03:00
crepe = "crepe"
2023-05-02 16:29:28 +03:00
2023-05-02 14:57:12 +03:00
class EnumFrameworkTypes(Enum):
pyTorch = "pyTorch"
onnx = "onnx"
2023-05-06 22:18:18 +03:00
class ServerAudioDeviceTypes(Enum):
audioinput = "audioinput"
audiooutput = "audiooutput"
2023-05-16 04:38:23 +03:00
2023-06-16 10:49:55 +03:00
RVCSampleMode: TypeAlias = Literal[
"production",
"testOfficial",
"testDDPNTorch",
"testDDPNONNX",
"testONNXFull",
]
2023-06-04 23:00:57 +03:00
2023-06-16 10:49:55 +03:00
def getSampleJsonAndModelIds(mode: RVCSampleMode):
if mode == "production":
2023-06-04 23:00:57 +03:00
return [
# "https://huggingface.co/wok000/vcclient_model/raw/main/samples_0001.json",
# "https://huggingface.co/wok000/vcclient_model/raw/main/samples_0002.json",
2023-06-16 10:49:55 +03:00
"https://huggingface.co/wok000/vcclient_model/raw/main/samples_0003_t2.json",
"https://huggingface.co/wok000/vcclient_model/raw/main/samples_0003_o2.json",
2023-06-04 23:00:57 +03:00
], [
2023-06-16 10:49:55 +03:00
("Tsukuyomi-chan_o", {"useIndex": False}),
2023-06-17 21:51:09 +03:00
("Amitaro_o", {"useIndex": False}),
("KikotoMahiro_o", {"useIndex": False}),
("TokinaShigure_o", {"useIndex": True}),
2023-06-04 23:00:57 +03:00
]
2023-06-16 10:49:55 +03:00
elif mode == "testOfficial":
2023-06-04 23:00:57 +03:00
return [
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_official_v1_v2.json",
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_ddpn_v1_v2.json",
], [
2023-06-16 10:49:55 +03:00
("test-official-v1-f0-48k-l9-hubert_t", {"useIndex": True}),
("test-official-v1-nof0-48k-l9-hubert_t", {"useIndex": False}),
("test-official-v2-f0-40k-l12-hubert_t", {"useIndex": False}),
("test-official-v2-nof0-40k-l12-hubert_t", {"useIndex": False}),
("test-official-v1-f0-48k-l9-hubert_o", {"useIndex": True}),
("test-official-v1-nof0-48k-l9-hubert_o", {"useIndex": False}),
("test-official-v2-f0-40k-l12-hubert_o", {"useIndex": False}),
("test-official-v2-nof0-40k-l12-hubert_o", {"useIndex": False}),
2023-06-04 23:00:57 +03:00
]
2023-06-16 10:49:55 +03:00
elif mode == "testDDPNTorch":
2023-06-04 23:00:57 +03:00
return [
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_official_v1_v2.json",
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_ddpn_v1_v2.json",
], [
2023-06-16 10:49:55 +03:00
("test-ddpn-v1-f0-48k-l9-hubert_t", {"useIndex": False}),
("test-ddpn-v1-nof0-48k-l9-hubert_t", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_t", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_t", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_jp_t", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_jp_t", {"useIndex": False}),
2023-06-04 23:00:57 +03:00
]
2023-06-16 10:49:55 +03:00
elif mode == "testDDPNONNX":
2023-06-04 23:00:57 +03:00
return [
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_official_v1_v2.json",
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_ddpn_v1_v2.json",
], [
2023-06-16 10:49:55 +03:00
("test-ddpn-v1-f0-48k-l9-hubert_o", {"useIndex": False}),
("test-ddpn-v1-nof0-48k-l9-hubert_o", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_o", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_o", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_jp_o", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_jp_o", {"useIndex": False}),
2023-06-04 23:00:57 +03:00
]
2023-06-16 10:49:55 +03:00
elif mode == "testONNXFull":
2023-06-04 23:00:57 +03:00
return [
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_official_v1_v2.json",
"https://huggingface.co/wok000/vcclient_model/raw/main/test/test_ddpn_v1_v2.json",
], [
2023-06-16 10:49:55 +03:00
("test-official-v1-f0-48k-l9-hubert_o_full", {"useIndex": False}),
("test-official-v1-nof0-48k-l9-hubert_o_full", {"useIndex": False}),
("test-official-v2-f0-40k-l12-hubert_o_full", {"useIndex": False}),
("test-official-v2-nof0-40k-l12-hubert_o_full", {"useIndex": False}),
("test-ddpn-v1-f0-48k-l9-hubert_o_full", {"useIndex": False}),
("test-ddpn-v1-nof0-48k-l9-hubert_o_full", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_o_full", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_o_full", {"useIndex": False}),
("test-ddpn-v2-f0-40k-l12-hubert_jp_o_full", {"useIndex": False}),
("test-ddpn-v2-nof0-40k-l12-hubert_jp_o_full", {"useIndex": False}),
2023-06-04 23:00:57 +03:00
]
else:
return [], []
2023-05-31 08:30:35 +03:00
2023-05-17 20:51:40 +03:00
RVC_MODEL_DIRNAME = "rvc"
2023-06-16 11:12:03 +03:00
MAX_SLOT_NUM = 10