2023-05-02 14:57:12 +03:00
|
|
|
import torch
|
|
|
|
import numpy as np
|
2023-05-31 08:30:35 +03:00
|
|
|
from const import EnumInferenceTypes
|
2023-05-02 14:57:12 +03:00
|
|
|
|
2023-05-03 07:14:00 +03:00
|
|
|
from voice_changer.RVC.inferencer.OnnxRVCInferencer import OnnxRVCInferencer
|
|
|
|
|
2023-07-06 20:17:29 +03:00
|
|
|
|
2023-05-03 07:14:00 +03:00
|
|
|
class OnnxRVCInferencerNono(OnnxRVCInferencer):
|
2023-09-06 02:04:39 +03:00
|
|
|
def loadModel(self, file: str, gpu: int, inferencerTypeVersion: str | None = None):
|
|
|
|
super().loadModel(file, gpu, inferencerTypeVersion)
|
2023-06-04 22:08:03 +03:00
|
|
|
self.setProps(EnumInferenceTypes.onnxRVCNono, file, self.isHalf, gpu)
|
2023-06-04 11:56:12 +03:00
|
|
|
return self
|
2023-05-31 08:30:35 +03:00
|
|
|
|
2023-05-02 14:57:12 +03:00
|
|
|
def infer(
|
|
|
|
self,
|
|
|
|
feats: torch.Tensor,
|
|
|
|
pitch_length: torch.Tensor,
|
|
|
|
pitch: torch.Tensor | None,
|
|
|
|
pitchf: torch.Tensor | None,
|
|
|
|
sid: torch.Tensor,
|
2023-07-01 10:45:25 +03:00
|
|
|
convert_length: int | None,
|
2023-05-02 14:57:12 +03:00
|
|
|
) -> torch.Tensor:
|
|
|
|
if self.isHalf:
|
|
|
|
audio1 = self.model.run(
|
|
|
|
["audio"],
|
|
|
|
{
|
|
|
|
"feats": feats.cpu().numpy().astype(np.float16),
|
|
|
|
"p_len": pitch_length.cpu().numpy().astype(np.int64),
|
|
|
|
"sid": sid.cpu().numpy().astype(np.int64),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
audio1 = self.model.run(
|
|
|
|
["audio"],
|
|
|
|
{
|
|
|
|
"feats": feats.cpu().numpy().astype(np.float32),
|
|
|
|
"p_len": pitch_length.cpu().numpy().astype(np.int64),
|
|
|
|
"sid": sid.cpu().numpy().astype(np.int64),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-09-06 02:04:39 +03:00
|
|
|
if self.inferencerTypeVersion == "v2.1" or self.inferencerTypeVersion == "v1.1":
|
|
|
|
res = audio1[0]
|
|
|
|
else:
|
|
|
|
res = np.array(audio1)[0][0, 0]
|
|
|
|
res = np.clip(res, -1.0, 1.0)
|
|
|
|
return torch.tensor(res)
|