2023-07-12 18:59:48 +03:00
|
|
|
import traceback
|
2023-07-13 21:33:04 +03:00
|
|
|
from data.ModelSlot import DiffusionSVCModelSlot
|
|
|
|
from voice_changer.DiffusionSVC.inferencer.InferencerManager import InferencerManager
|
|
|
|
from voice_changer.DiffusionSVC.pipeline.Pipeline import Pipeline
|
2023-07-14 07:54:08 +03:00
|
|
|
from voice_changer.DiffusionSVC.pitchExtractor.PitchExtractorManager import PitchExtractorManager
|
2023-07-12 18:59:48 +03:00
|
|
|
|
|
|
|
from voice_changer.RVC.deviceManager.DeviceManager import DeviceManager
|
|
|
|
from voice_changer.RVC.embedder.EmbedderManager import EmbedderManager
|
|
|
|
|
2023-07-14 22:45:27 +03:00
|
|
|
import torch
|
|
|
|
from torchaudio.transforms import Resample
|
2023-07-12 18:59:48 +03:00
|
|
|
|
2023-07-14 22:45:27 +03:00
|
|
|
|
|
|
|
def createPipeline(modelSlot: DiffusionSVCModelSlot, gpu: int, f0Detector: str, inputSampleRate: int, outputSampleRate: int):
|
2023-07-12 18:59:48 +03:00
|
|
|
dev = DeviceManager.get_instance().getDevice(gpu)
|
2023-07-13 21:33:04 +03:00
|
|
|
# half = DeviceManager.get_instance().halfPrecisionAvailable(gpu)
|
|
|
|
half = False
|
|
|
|
|
|
|
|
# Inferencer 生成
|
|
|
|
try:
|
|
|
|
inferencer = InferencerManager.getInferencer(modelSlot.modelType, modelSlot.modelFile, gpu)
|
|
|
|
except Exception as e:
|
|
|
|
print("[Voice Changer] exception! loading inferencer", e)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
# Embedder 生成
|
|
|
|
try:
|
|
|
|
embedder = EmbedderManager.getEmbedder(
|
|
|
|
modelSlot.embedder,
|
|
|
|
# emmbedderFilename,
|
|
|
|
half,
|
|
|
|
dev,
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
print("[Voice Changer] exception! loading embedder", e)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
# pitchExtractor
|
|
|
|
pitchExtractor = PitchExtractorManager.getPitchExtractor(f0Detector, gpu)
|
|
|
|
|
2023-07-14 22:45:27 +03:00
|
|
|
resamplerIn = Resample(inputSampleRate, 16000, dtype=torch.int16).to(dev)
|
|
|
|
resamplerOut = Resample(modelSlot.samplingRate, outputSampleRate, dtype=torch.int16).to(dev)
|
|
|
|
|
2023-07-13 21:33:04 +03:00
|
|
|
pipeline = Pipeline(
|
|
|
|
embedder,
|
|
|
|
inferencer,
|
|
|
|
pitchExtractor,
|
|
|
|
modelSlot.samplingRate,
|
|
|
|
dev,
|
|
|
|
half,
|
2023-07-14 22:45:27 +03:00
|
|
|
resamplerIn,
|
|
|
|
resamplerOut
|
2023-07-13 21:33:04 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
return pipeline
|
2023-07-12 18:59:48 +03:00
|
|
|
|