voice-changer/server/voice_changer/DiffusionSVC/pitchExtractor/PitchExtractorManager.py

52 lines
2.3 KiB
Python
Raw Normal View History

2023-07-14 07:54:08 +03:00
from typing import Protocol
from const import PitchExtractorType
2023-07-15 00:07:33 +03:00
from voice_changer.DiffusionSVC.pitchExtractor.CrepeOnnxPitchExtractor import CrepeOnnxPitchExtractor
2023-07-14 23:57:20 +03:00
from voice_changer.DiffusionSVC.pitchExtractor.CrepePitchExtractor import CrepePitchExtractor
2023-07-14 23:40:40 +03:00
from voice_changer.DiffusionSVC.pitchExtractor.DioPitchExtractor import DioPitchExtractor
2023-07-14 07:54:08 +03:00
from voice_changer.DiffusionSVC.pitchExtractor.HarvestPitchExtractor import HarvestPitchExtractor
from voice_changer.DiffusionSVC.pitchExtractor.PitchExtractor import PitchExtractor
2023-07-15 03:17:19 +03:00
from voice_changer.DiffusionSVC.pitchExtractor.RMVPEPitchExtractor import RMVPEPitchExtractor
2023-07-14 07:54:08 +03:00
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
class PitchExtractorManager(Protocol):
currentPitchExtractor: PitchExtractor | None = None
params: VoiceChangerParams
@classmethod
def initialize(cls, params: VoiceChangerParams):
cls.params = params
@classmethod
def getPitchExtractor(
cls, pitchExtractorType: PitchExtractorType, gpu: int
) -> PitchExtractor:
cls.currentPitchExtractor = cls.loadPitchExtractor(pitchExtractorType, gpu)
return cls.currentPitchExtractor
@classmethod
def loadPitchExtractor(
cls, pitchExtractorType: PitchExtractorType, gpu: int
) -> PitchExtractor:
if pitchExtractorType == "harvest":
return HarvestPitchExtractor()
2023-07-14 23:40:40 +03:00
elif pitchExtractorType == "dio":
return DioPitchExtractor()
2023-07-14 23:57:20 +03:00
elif pitchExtractorType == "crepe":
return CrepePitchExtractor()
2023-07-15 00:07:33 +03:00
elif pitchExtractorType == "crepe_tiny":
return CrepeOnnxPitchExtractor(pitchExtractorType, cls.params.crepe_onnx_tiny, gpu)
elif pitchExtractorType == "crepe_full":
return CrepeOnnxPitchExtractor(pitchExtractorType, cls.params.crepe_onnx_full, gpu)
2023-07-15 03:17:19 +03:00
elif pitchExtractorType == "rmvpe":
2023-07-15 04:01:42 +03:00
print("pitchExtractorType", pitchExtractorType)
2023-07-15 03:17:19 +03:00
return RMVPEPitchExtractor(cls.params.rmvpe, gpu)
2023-07-14 07:54:08 +03:00
else:
# return hubert as default
2023-07-15 04:01:42 +03:00
print("[Voice Changer] PitchExctractor not found", pitchExtractorType)
print(" fallback to dio")
return DioPitchExtractor()
# raise RuntimeError(
# "[Voice Changer] PitchExctractor not found", pitchExtractorType
# )