voice-changer/server/voice_changer/VoiceChangerManager.py

29 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
class VoiceChangerManager():
@classmethod
def get_instance(cls):
if not hasattr(cls, "_instance"):
cls._instance = cls()
return cls._instance
2023-01-07 14:07:39 +03:00
def loadModel(self, config, model, onnx_model):
2022-12-31 10:02:53 +03:00
if hasattr(self, 'voiceChanger') == True:
self.voiceChanger.destroy()
2023-01-07 14:07:39 +03:00
self.voiceChanger = VoiceChanger(config, model, onnx_model)
2022-12-31 10:02:53 +03:00
2023-01-04 20:28:36 +03:00
def changeVoice(self, gpu, srcId, dstId, timestamp, convertChunkNum, crossFadeLowerValue, crossFadeOffsetRate, crossFadeEndRate, unpackedData):
if hasattr(self, 'voiceChanger') == True:
return self.voiceChanger.on_request(gpu, srcId, dstId, timestamp, convertChunkNum, crossFadeLowerValue, crossFadeOffsetRate, crossFadeEndRate, unpackedData)
else:
print("Voice Change is not loaded. Did you load a correct model?")
return np.zeros(1).astype(np.int16)
def changeVoice_old(self, gpu, srcId, dstId, timestamp, prefixChunkSize, unpackedData):
2022-12-31 10:02:53 +03:00
if hasattr(self, 'voiceChanger') == True:
return self.voiceChanger.on_request(gpu, srcId, dstId, timestamp, prefixChunkSize, unpackedData)
else:
print("Voice Change is not loaded. Did you load a correct model?")
return np.zeros(1).astype(np.int16)