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

48 lines
2.1 KiB
Python
Raw Normal View History

2023-05-02 16:29:28 +03:00
from typing import Protocol
from const import PitchExtractorType
from voice_changer.RVC.pitchExtractor.CrepeOnnxPitchExtractor import CrepeOnnxPitchExtractor
2023-05-02 16:29:28 +03:00
from voice_changer.RVC.pitchExtractor.DioPitchExtractor import DioPitchExtractor
from voice_changer.RVC.pitchExtractor.HarvestPitchExtractor import HarvestPitchExtractor
2023-05-20 10:33:17 +03:00
from voice_changer.RVC.pitchExtractor.CrepePitchExtractor import CrepePitchExtractor
2023-05-02 16:29:28 +03:00
from voice_changer.RVC.pitchExtractor.PitchExtractor import PitchExtractor
2023-07-18 17:02:06 +03:00
from voice_changer.RVC.pitchExtractor.RMVPEPitchExtractor import RMVPEPitchExtractor
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
2023-05-02 16:29:28 +03:00
class PitchExtractorManager(Protocol):
currentPitchExtractor: PitchExtractor | None = None
params: VoiceChangerParams
@classmethod
def initialize(cls, params: VoiceChangerParams):
cls.params = params
2023-05-02 16:29:28 +03:00
@classmethod
def getPitchExtractor(
cls, pitchExtractorType: PitchExtractorType, gpu: int
2023-05-02 16:29:28 +03:00
) -> PitchExtractor:
cls.currentPitchExtractor = cls.loadPitchExtractor(pitchExtractorType, gpu)
2023-05-02 16:29:28 +03:00
return cls.currentPitchExtractor
@classmethod
def loadPitchExtractor(
cls, pitchExtractorType: PitchExtractorType, gpu: int
2023-05-02 16:29:28 +03:00
) -> PitchExtractor:
if pitchExtractorType == "harvest":
2023-05-02 16:29:28 +03:00
return HarvestPitchExtractor()
elif pitchExtractorType == "dio":
2023-05-02 16:29:28 +03:00
return DioPitchExtractor()
elif pitchExtractorType == "crepe":
2023-07-23 17:01:35 +03:00
return CrepePitchExtractor(gpu)
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-18 17:02:06 +03:00
elif pitchExtractorType == "rmvpe":
return RMVPEPitchExtractor(cls.params.rmvpe, gpu)
2023-05-02 16:29:28 +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()