2022-12-31 10:02:53 +03:00
|
|
|
import numpy as np
|
2022-12-31 10:08:14 +03:00
|
|
|
from voice_changer.VoiceChanger import VoiceChanger
|
2023-04-10 18:21:17 +03:00
|
|
|
from const import ModelType
|
2023-04-27 17:38:25 +03:00
|
|
|
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
|
2022-12-31 10:02:53 +03:00
|
|
|
|
2023-01-29 03:42:45 +03:00
|
|
|
|
2023-04-27 17:38:25 +03:00
|
|
|
class VoiceChangerManager(object):
|
|
|
|
_instance = None
|
|
|
|
voiceChanger: VoiceChanger = None
|
|
|
|
|
2022-12-31 10:02:53 +03:00
|
|
|
@classmethod
|
2023-04-27 17:38:25 +03:00
|
|
|
def get_instance(cls, params: VoiceChangerParams):
|
|
|
|
if cls._instance is None:
|
2022-12-31 10:02:53 +03:00
|
|
|
cls._instance = cls()
|
2023-03-16 02:11:38 +03:00
|
|
|
cls._instance.voiceChanger = VoiceChanger(params)
|
2022-12-31 10:02:53 +03:00
|
|
|
return cls._instance
|
|
|
|
|
2023-04-16 03:56:12 +03:00
|
|
|
def loadModel(self, props):
|
|
|
|
info = self.voiceChanger.loadModel(props)
|
2023-04-14 05:03:52 +03:00
|
|
|
if hasattr(info, "status") and info["status"] == "NG":
|
|
|
|
return info
|
|
|
|
else:
|
|
|
|
info["status"] = "OK"
|
|
|
|
return info
|
2022-12-31 10:02:53 +03:00
|
|
|
|
2023-01-07 18:25:21 +03:00
|
|
|
def get_info(self):
|
2023-04-27 17:38:25 +03:00
|
|
|
if hasattr(self, "voiceChanger"):
|
2023-01-10 16:49:16 +03:00
|
|
|
info = self.voiceChanger.get_info()
|
2023-01-29 03:42:45 +03:00
|
|
|
info["status"] = "OK"
|
2023-01-10 16:49:16 +03:00
|
|
|
return info
|
2023-01-07 18:25:21 +03:00
|
|
|
else:
|
2023-01-29 03:42:45 +03:00
|
|
|
return {"status": "ERROR", "msg": "no model loaded"}
|
2023-01-07 18:25:21 +03:00
|
|
|
|
2023-04-10 02:13:17 +03:00
|
|
|
def update_settings(self, key: str, val: any):
|
2023-04-27 17:38:25 +03:00
|
|
|
if hasattr(self, "voiceChanger"):
|
2023-04-10 02:13:17 +03:00
|
|
|
info = self.voiceChanger.update_settings(key, val)
|
2023-01-29 03:42:45 +03:00
|
|
|
info["status"] = "OK"
|
2023-01-10 16:49:16 +03:00
|
|
|
return info
|
2023-01-07 18:25:21 +03:00
|
|
|
else:
|
2023-01-29 03:42:45 +03:00
|
|
|
return {"status": "ERROR", "msg": "no model loaded"}
|
2023-01-08 10:18:20 +03:00
|
|
|
|
2023-03-07 17:14:14 +03:00
|
|
|
def changeVoice(self, receivedData: any):
|
2023-04-27 17:38:25 +03:00
|
|
|
if hasattr(self, "voiceChanger") is True:
|
2023-03-07 17:14:14 +03:00
|
|
|
return self.voiceChanger.on_request(receivedData)
|
2023-01-04 20:28:36 +03:00
|
|
|
else:
|
|
|
|
print("Voice Change is not loaded. Did you load a correct model?")
|
2023-02-20 22:07:43 +03:00
|
|
|
return np.zeros(1).astype(np.int16), []
|
2023-04-10 18:21:17 +03:00
|
|
|
|
|
|
|
def switchModelType(self, modelType: ModelType):
|
|
|
|
return self.voiceChanger.switchModelType(modelType)
|
|
|
|
|
|
|
|
def getModelType(self):
|
|
|
|
return self.voiceChanger.getModelType()
|
2023-04-13 02:00:28 +03:00
|
|
|
|
|
|
|
def export2onnx(self):
|
|
|
|
return self.voiceChanger.export2onnx()
|