voice-changer/server/voice_changer/RVC/pitchExtractor/PitchExtractorManager.py
2023-05-02 22:29:28 +09:00

37 lines
1.3 KiB
Python

from typing import Protocol
from const import EnumPitchExtractorTypes
from voice_changer.RVC.pitchExtractor.DioPitchExtractor import DioPitchExtractor
from voice_changer.RVC.pitchExtractor.HarvestPitchExtractor import HarvestPitchExtractor
from voice_changer.RVC.pitchExtractor.PitchExtractor import PitchExtractor
class PitchExtractorManager(Protocol):
currentPitchExtractor: PitchExtractor | None = None
@classmethod
def getPitchExtractor(
cls, pitchExtractorType: EnumPitchExtractorTypes
) -> PitchExtractor:
cls.currentPitchExtractor = cls.loadPitchExtractor(pitchExtractorType)
return cls.currentPitchExtractor
@classmethod
def loadPitchExtractor(
cls, pitchExtractorType: EnumPitchExtractorTypes
) -> PitchExtractor:
if (
pitchExtractorType == EnumPitchExtractorTypes.harvest
or pitchExtractorType == EnumPitchExtractorTypes.harvest.value
):
return HarvestPitchExtractor()
elif (
pitchExtractorType == EnumPitchExtractorTypes.dio
or pitchExtractorType == EnumPitchExtractorTypes.dio.value
):
return DioPitchExtractor()
else:
# return hubert as default
raise RuntimeError(
"[Voice Changer] PitchExctractor not found", pitchExtractorType
)