From 958b03bd5a1c8116d2859333c183b35dd34624f5 Mon Sep 17 00:00:00 2001 From: w-okada Date: Tue, 14 Nov 2023 05:39:07 +0900 Subject: [PATCH] bugfix: timer update --- client/demo/dist/assets/gui_settings/GUI.json | 2 +- client/demo/public/assets/gui_settings/GUI.json | 2 +- server/voice_changer/VoiceChanger.py | 11 +++++++---- server/voice_changer/VoiceChangerV2.py | 10 +++++++--- server/voice_changer/utils/Timer.py | 12 ++++++------ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/client/demo/dist/assets/gui_settings/GUI.json b/client/demo/dist/assets/gui_settings/GUI.json index 745ad94f..ccf3be9e 100644 --- a/client/demo/dist/assets/gui_settings/GUI.json +++ b/client/demo/dist/assets/gui_settings/GUI.json @@ -22,7 +22,7 @@ "name": "configArea", "options": { "detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx"], - "inputChunkNums": [1, 2, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384] + "inputChunkNums": [1, 2, 4, 6, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384] } } ] diff --git a/client/demo/public/assets/gui_settings/GUI.json b/client/demo/public/assets/gui_settings/GUI.json index 745ad94f..ccf3be9e 100644 --- a/client/demo/public/assets/gui_settings/GUI.json +++ b/client/demo/public/assets/gui_settings/GUI.json @@ -22,7 +22,7 @@ "name": "configArea", "options": { "detectors": ["dio", "harvest", "crepe", "crepe_full", "crepe_tiny", "rmvpe", "rmvpe_onnx"], - "inputChunkNums": [1, 2, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384] + "inputChunkNums": [1, 2, 4, 6, 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 2048, 4096, 8192, 16384] } } ] diff --git a/server/voice_changer/VoiceChanger.py b/server/voice_changer/VoiceChanger.py index 07209115..b934dba5 100755 --- a/server/voice_changer/VoiceChanger.py +++ b/server/voice_changer/VoiceChanger.py @@ -11,7 +11,7 @@ from mods.log_control import VoiceChangaerLogger from voice_changer.IORecorder import IORecorder -from voice_changer.utils.Timer import Timer +from voice_changer.utils.Timer import Timer2 from voice_changer.utils.VoiceChangerIF import VoiceChangerIF from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel from Exceptions import ( @@ -191,7 +191,7 @@ class VoiceChanger(VoiceChangerIF): processing_sampling_rate = self.voiceChanger.get_processing_sampling_rate() # 前処理 - with Timer("pre-process") as t: + with Timer2("pre-process", False) as t: if self.settings.inputSampleRate != processing_sampling_rate: newData = cast( AudioInOut, @@ -211,10 +211,11 @@ class VoiceChanger(VoiceChangerIF): self._generate_strength(crossfade_frame) data = self.voiceChanger.generate_input(newData, block_frame, crossfade_frame, sola_search_frame) + t.record("fin") preprocess_time = t.secs # 変換処理 - with Timer("main-process") as t: + with Timer2("main-process", False) as t: # Inference audio = self.voiceChanger.inference(data) @@ -256,10 +257,11 @@ class VoiceChanger(VoiceChangerIF): else: self.sola_buffer = audio[-crossfade_frame:] * self.np_prev_strength # self.sola_buffer = audio[- crossfade_frame:] + t.record("fin") mainprocess_time = t.secs # 後処理 - with Timer("post-process") as t: + with Timer2("post-process", False) as t: result = result.astype(np.int16) if self.settings.outputSampleRate != processing_sampling_rate: @@ -293,6 +295,7 @@ class VoiceChanger(VoiceChangerIF): if self.settings.recordIO == 1: self.ioRecorder.writeInput(receivedData) self.ioRecorder.writeOutput(outputData.tobytes()) + t.record("fin") postprocess_time = t.secs diff --git a/server/voice_changer/VoiceChangerV2.py b/server/voice_changer/VoiceChangerV2.py index 8bf72fca..ba8fad58 100644 --- a/server/voice_changer/VoiceChangerV2.py +++ b/server/voice_changer/VoiceChangerV2.py @@ -23,7 +23,7 @@ from mods.log_control import VoiceChangaerLogger from voice_changer.IORecorder import IORecorder -from voice_changer.utils.Timer import Timer +from voice_changer.utils.Timer import Timer2 from voice_changer.utils.VoiceChangerIF import VoiceChangerIF from voice_changer.utils.VoiceChangerModel import AudioInOut, VoiceChangerModel from Exceptions import ( @@ -146,6 +146,7 @@ class VoiceChangerV2(VoiceChangerIF): self.settings.outputSampleRate, # 16000, ) + print(f"-------------------------- - - - {self.settings.inputSampleRate}, {self.settings.outputSampleRate}") if key == "recordIO" and val == 0: if hasattr(self, "ioRecorder"): self.ioRecorder.close() @@ -216,7 +217,7 @@ class VoiceChangerV2(VoiceChangerIF): if self.voiceChanger is None: raise VoiceChangerIsNotSelectedException("Voice Changer is not selected.") - with Timer("main-process") as t: + with Timer2("main-process", False) as t: processing_sampling_rate = self.voiceChanger.get_processing_sampling_rate() if self.noCrossFade: # Beatrice, LLVC @@ -282,7 +283,7 @@ class VoiceChangerV2(VoiceChangerIF): mainprocess_time = t.secs # 後処理 - with Timer("post-process") as t: + with Timer2("post-process", False) as t: result = result.astype(np.int16) print_convert_processing(f" Output data size of {result.shape[0]}/{processing_sampling_rate}hz {result .shape[0]}/{self.settings.outputSampleRate}hz") @@ -299,6 +300,9 @@ class VoiceChangerV2(VoiceChangerIF): outputData = result if self.settings.recordIO == 1: + print(f"-------------------------- - - -shapes::: {receivedData.shape}, {outputData.shape}") + print(f"-------------------------- - - -shapes::: {receivedData.dtype}, {outputData.dtype}") + print(f"-------------------------- - - -shapes::: {receivedData[0:10]}, {outputData[0:10]}") self.ioRecorder.writeInput(receivedData) self.ioRecorder.writeOutput(outputData.tobytes()) diff --git a/server/voice_changer/utils/Timer.py b/server/voice_changer/utils/Timer.py index 1a2107b2..43dc0b16 100644 --- a/server/voice_changer/utils/Timer.py +++ b/server/voice_changer/utils/Timer.py @@ -1,9 +1,10 @@ import time import inspect +from typing import Dict, List class Timer(object): - storedSecs = {} # Class variable + storedSecs: Dict[str, Dict[str, List[float]]] = {} # Class variable def __init__(self, title: str, enalbe: bool = True): self.title = title @@ -24,7 +25,7 @@ class Timer(object): line_number = frame.lineno self.key = f"{title}_{filename}_{line_number}" if self.key not in self.storedSecs: - self.storedSecs[self.key] = [] + self.storedSecs[self.key] = {} def __enter__(self): if self.enable is False: @@ -39,12 +40,12 @@ class Timer(object): self.secs = self.end - self.start self.msecs = self.secs * 1000 # millisecs self.storedSecs[self.key].append(self.secs) - self.storedSecs[self.key] = self.storedSecs[self.key][-self.maxStores:] + self.storedSecs[self.key] = self.storedSecs[self.key][-self.maxStores :] self.avrSecs = sum(self.storedSecs[self.key]) / len(self.storedSecs[self.key]) class Timer2(object): - storedSecs = {} # Class variable + storedSecs: Dict[str, Dict[str, List[float]]] = {} # Class variable def __init__(self, title: str, enalbe: bool = True): self.title = title @@ -82,7 +83,7 @@ class Timer2(object): if self.lapkey not in self.storedSecs[self.key]: self.storedSecs[self.key][self.lapkey] = [] self.storedSecs[self.key][self.lapkey].append(self.current - prev) - self.storedSecs[self.key][self.lapkey] = self.storedSecs[self.key][self.lapkey][-self.maxStores:] + self.storedSecs[self.key][self.lapkey] = self.storedSecs[self.key][self.lapkey][-self.maxStores :] def __exit__(self, *_): if self.enable is False: @@ -93,4 +94,3 @@ class Timer2(object): section = key.split("_")[-1] milisecAvr = sum(val) / len(val) * 1000 print(f"{section}: {milisecAvr} msec") -