Skip to content

Commit

Permalink
refactor: use external package for monotonic alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed Nov 6, 2024
1 parent 59996ff commit 4fc282e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 70 deletions.
42 changes: 19 additions & 23 deletions TTS/tts/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import numpy as np
import torch
from monotonic_alignment_search import maximum_path as maximum_path_cython
from scipy.stats import betabinom
from torch.nn import functional as F

try:
from TTS.tts.utils.monotonic_align.core import maximum_path_c

CYTHON = True
except ModuleNotFoundError:
CYTHON = False
CYTHON = True


class StandardScaler:
Expand Down Expand Up @@ -174,23 +170,23 @@ def maximum_path(value, mask):
return maximum_path_numpy(value, mask)


def maximum_path_cython(value, mask):
"""Cython optimised version.
Shapes:
- value: :math:`[B, T_en, T_de]`
- mask: :math:`[B, T_en, T_de]`
"""
value = value * mask
device = value.device
dtype = value.dtype
value = value.data.cpu().numpy().astype(np.float32)
path = np.zeros_like(value).astype(np.int32)
mask = mask.data.cpu().numpy()

t_x_max = mask.sum(1)[:, 0].astype(np.int32)
t_y_max = mask.sum(2)[:, 0].astype(np.int32)
maximum_path_c(path, value, t_x_max, t_y_max)
return torch.from_numpy(path).to(device=device, dtype=dtype)
# def maximum_path_cython(value, mask):
# """Cython optimised version.
# Shapes:
# - value: :math:`[B, T_en, T_de]`
# - mask: :math:`[B, T_en, T_de]`
# """
# value = value * mask
# device = value.device
# dtype = value.dtype
# value = value.data.cpu().numpy().astype(np.float32)
# path = np.zeros_like(value).astype(np.int32)
# mask = mask.data.cpu().numpy()

# t_x_max = mask.sum(1)[:, 0].astype(np.int32)
# t_y_max = mask.sum(2)[:, 0].astype(np.int32)
# maximum_path_c(path, value, t_x_max, t_y_max)
# return torch.from_numpy(path).to(device=device, dtype=dtype)


def maximum_path_numpy(value, mask, max_neg_val=None):
Expand Down
Empty file.
47 changes: 0 additions & 47 deletions TTS/tts/utils/monotonic_align/core.pyx

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies = [
# Coqui stack
"coqui-tts-trainer>=0.1.4,<0.2.0",
"coqpit>=0.0.16",
"monotonic-alignment-search>=0.1.0",
# Gruut + supported languages
"gruut[de,es,fr]>=2.4.0",
# Tortoise
Expand Down

0 comments on commit 4fc282e

Please sign in to comment.