voice-changer/server/voice_changer/VoiceChangerManager.py

40 lines
1.3 KiB
Python
Raw Normal View History

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
2022-12-31 10:02:53 +03:00
2023-01-29 03:42:45 +03:00
2022-12-31 10:02:53 +03:00
class VoiceChangerManager():
@classmethod
def get_instance(cls):
if not hasattr(cls, "_instance"):
cls._instance = cls()
2023-01-29 03:42:45 +03:00
cls._instance.voiceChanger = VoiceChanger()
2022-12-31 10:02:53 +03:00
return cls._instance
2023-01-07 14:07:39 +03:00
def loadModel(self, config, model, onnx_model):
2023-01-10 16:49:16 +03:00
info = self.voiceChanger.loadModel(config, model, onnx_model)
2023-01-29 03:42:45 +03:00
info["status"] = "OK"
2023-01-10 16:49:16 +03:00
return info
2022-12-31 10:02:53 +03:00
2023-01-07 18:25:21 +03:00
def get_info(self):
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-01-29 03:42:45 +03:00
def update_setteings(self, key: str, val: any):
2023-01-07 18:25:21 +03:00
if hasattr(self, 'voiceChanger'):
2023-01-10 16:49:16 +03:00
info = self.voiceChanger.update_setteings(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-01-29 03:42:45 +03:00
def changeVoice(self, unpackedData: any):
2023-01-04 20:28:36 +03:00
if hasattr(self, 'voiceChanger') == True:
2023-01-08 10:18:20 +03:00
return self.voiceChanger.on_request(unpackedData)
2023-01-04 20:28:36 +03:00
else:
print("Voice Change is not loaded. Did you load a correct model?")
return np.zeros(1).astype(np.int16)