WIP: refactor

This commit is contained in:
w-okada 2023-07-15 23:39:02 +09:00
parent 33e156ef9a
commit 9eef8fcb11
4 changed files with 34 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import onnxruntime
from voice_changer.IORecorder import IORecorder from voice_changer.IORecorder import IORecorder
from voice_changer.utils.Timer import Timer from voice_changer.utils.Timer import Timer
from voice_changer.utils.VoiceChangerIF import VoiceChangerIF
from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel
from Exceptions import ( from Exceptions import (
DeviceCannotSupportHalfPrecisionException, DeviceCannotSupportHalfPrecisionException,
@ -59,7 +60,7 @@ class VoiceChangerSettings:
strData: list[str] = field(default_factory=lambda: []) strData: list[str] = field(default_factory=lambda: [])
class VoiceChanger: class VoiceChanger(VoiceChangerIF):
ioRecorder: IORecorder ioRecorder: IORecorder
sola_buffer: AudioInOut sola_buffer: AudioInOut
@ -83,9 +84,6 @@ class VoiceChanger:
def setModel(self, model: Any): def setModel(self, model: Any):
self.voiceChanger = model self.voiceChanger = model
def getModelType(self):
return {"status": "OK", "vc": "-----"}
def get_info(self): def get_info(self):
data = asdict(self.settings) data = asdict(self.settings)
if self.voiceChanger is not None: if self.voiceChanger is not None:

View File

@ -280,9 +280,6 @@ class VoiceChangerManager(ServerDeviceCallbacks):
print("Voice Change is not loaded. Did you load a correct model?") print("Voice Change is not loaded. Did you load a correct model?")
return np.zeros(1).astype(np.int16), [] return np.zeros(1).astype(np.int16), []
def getModelType(self):
return self.voiceChanger.getModelType()
def export2onnx(self): def export2onnx(self):
return self.voiceChanger.export2onnx() return self.voiceChanger.export2onnx()

View File

@ -22,6 +22,7 @@ import onnxruntime
from voice_changer.IORecorder import IORecorder from voice_changer.IORecorder import IORecorder
from voice_changer.utils.Timer import Timer from voice_changer.utils.Timer import Timer
from voice_changer.utils.VoiceChangerIF import VoiceChangerIF
from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel
from Exceptions import ( from Exceptions import (
DeviceCannotSupportHalfPrecisionException, DeviceCannotSupportHalfPrecisionException,
@ -69,7 +70,7 @@ class VoiceChangerV2Settings:
strData: list[str] = field(default_factory=lambda: []) strData: list[str] = field(default_factory=lambda: [])
class VoiceChangerV2: class VoiceChangerV2(VoiceChangerIF):
ioRecorder: IORecorder ioRecorder: IORecorder
sola_buffer: AudioInOut sola_buffer: AudioInOut
@ -198,7 +199,7 @@ class VoiceChangerV2:
block_frame = receivedData.shape[0] block_frame = receivedData.shape[0]
crossfade_frame = min(self.settings.crossFadeOverlapSize, block_frame) crossfade_frame = min(self.settings.crossFadeOverlapSize, block_frame)
self._generate_strength(crossfade_frame) self._generate_strength(crossfade_frame)
# data = self.voiceChanger.generate_input(newData, block_frame, crossfade_frame, sola_search_frame) # data = self.voiceChanger.generate_input(newData, block_frame, crossfade_frame, sola_search_frame)
audio = self.voiceChanger.inference( audio = self.voiceChanger.inference(
receivedData, receivedData,
crossfade_frame=crossfade_frame, crossfade_frame=crossfade_frame,
@ -242,7 +243,7 @@ class VoiceChangerV2:
else: else:
self.sola_buffer = audio[-crossfade_frame:] * self.np_prev_strength self.sola_buffer = audio[-crossfade_frame:] * self.np_prev_strength
# self.sola_buffer = audio[- crossfade_frame:] # self.sola_buffer = audio[- crossfade_frame:]
mainprocess_time = t.secs mainprocess_time = t.secs
# 後処理 # 後処理

View File

@ -0,0 +1,28 @@
from typing import Any, Protocol
from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel
class VoiceChangerIF(Protocol):
def get_processing_sampling_rate() -> int:
...
def get_info(self) -> dict[str, Any]:
...
def get_performance(self) -> list[int]:
...
def setModel(model: VoiceChangerModel) -> None:
...
def update_settings(self, key: str, val: int | float | str) -> bool:
...
def on_request(receivedData: AudioInOut) -> tuple[AudioInOut, list[int | float]]:
...
def export2onnx() -> Any:
...