2022-12-31 16:02:53 +09:00
|
|
|
import numpy as np
|
2022-12-31 16:08:14 +09:00
|
|
|
from voice_changer.VoiceChanger import VoiceChanger
|
2023-01-08 00:25:21 +09:00
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from fastapi.encoders import jsonable_encoder
|
2022-12-31 16:02:53 +09:00
|
|
|
|
|
|
|
class VoiceChangerManager():
|
|
|
|
@classmethod
|
|
|
|
def get_instance(cls):
|
|
|
|
if not hasattr(cls, "_instance"):
|
|
|
|
cls._instance = cls()
|
|
|
|
return cls._instance
|
|
|
|
|
2023-01-07 20:07:39 +09:00
|
|
|
def loadModel(self, config, model, onnx_model):
|
2023-01-08 21:56:39 +09:00
|
|
|
if hasattr(self, 'voiceChanger') == False:
|
|
|
|
self.voiceChanger = VoiceChanger(config)
|
2023-01-10 22:49:16 +09:00
|
|
|
info = self.voiceChanger.loadModel(config, model, onnx_model)
|
|
|
|
info["status"]="OK"
|
|
|
|
return info
|
2022-12-31 16:02:53 +09:00
|
|
|
|
2023-01-08 00:25:21 +09:00
|
|
|
def get_info(self):
|
|
|
|
if hasattr(self, 'voiceChanger'):
|
2023-01-10 22:49:16 +09:00
|
|
|
info = self.voiceChanger.get_info()
|
|
|
|
info["status"]="OK"
|
|
|
|
return info
|
2023-01-08 00:25:21 +09:00
|
|
|
else:
|
2023-01-10 22:49:16 +09:00
|
|
|
return {"status":"ERROR", "msg":"no model loaded"}
|
2023-01-08 00:25:21 +09:00
|
|
|
|
2023-01-08 16:18:20 +09:00
|
|
|
def update_setteings(self, key:str, val:any):
|
2023-01-08 00:25:21 +09:00
|
|
|
if hasattr(self, 'voiceChanger'):
|
2023-01-10 22:49:16 +09:00
|
|
|
info = self.voiceChanger.update_setteings(key, val)
|
|
|
|
info["status"]="OK"
|
|
|
|
return info
|
2023-01-08 00:25:21 +09:00
|
|
|
else:
|
2023-01-10 22:49:16 +09:00
|
|
|
return {"status":"ERROR", "msg":"no model loaded"}
|
2023-01-08 16:18:20 +09:00
|
|
|
|
2023-01-08 17:58:27 +09:00
|
|
|
def changeVoice(self, unpackedData:any):
|
2023-01-05 02:28:36 +09:00
|
|
|
if hasattr(self, 'voiceChanger') == True:
|
2023-01-08 16:18:20 +09:00
|
|
|
return self.voiceChanger.on_request(unpackedData)
|
2023-01-05 02:28:36 +09:00
|
|
|
else:
|
|
|
|
print("Voice Change is not loaded. Did you load a correct model?")
|
|
|
|
return np.zeros(1).astype(np.int16)
|