Skip to content

Commit

Permalink
Export multispeaker onnx (coqui-ai#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
erogol authored and Tindell committed Aug 14, 2023
1 parent 1f2231a commit 6affbb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 0 additions & 2 deletions TTS/tts/layers/bark/hubert/kmeans_hubert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from torchaudio.functional import resample
from transformers import HubertModel

logging.root.setLevel(logging.ERROR)


def round_down_nearest_multiple(num, divisor):
return num // divisor * divisor
Expand Down
15 changes: 8 additions & 7 deletions TTS/tts/models/vits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,19 +1876,20 @@ def onnx_inference(text, text_lengths, scales, sid=None):
def load_onnx(self, model_path: str, cuda=False):
import onnxruntime as ort

providers = ["CPUExecutionProvider" if cuda is False else "CUDAExecutionProvider"]
providers = [
"CPUExecutionProvider"
if cuda is False
else ("CUDAExecutionProvider", {"cudnn_conv_algo_search": "DEFAULT"})
]
sess_options = ort.SessionOptions()
self.onnx_sess = ort.InferenceSession(
model_path,
sess_options=sess_options,
providers=providers,
)

def inference_onnx(self, x, x_lengths=None):
"""ONNX inference (only single speaker models are supported)
TODO: implement multi speaker support.
"""
def inference_onnx(self, x, x_lengths=None, speaker_id=None):
"""ONNX inference"""

if isinstance(x, torch.Tensor):
x = x.cpu().numpy()
Expand All @@ -1908,7 +1909,7 @@ def inference_onnx(self, x, x_lengths=None):
"input": x,
"input_lengths": x_lengths,
"scales": scales,
"sid": None,
"sid": torch.tensor([speaker_id]).cpu().numpy(),
},
)
return audio[0][0]
Expand Down

0 comments on commit 6affbb4

Please sign in to comment.