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