Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export multispeaker onnx #2743

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TTS/tts/layers/bark/hubert/kmeans_hubert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from torch import nn
from torchaudio.functional import resample
from transformers import HubertModel


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 @@ -1875,19 +1875,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 @@ -1907,7 +1908,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