Skip to content

Commit ac36db8

Browse files
committed
fix _get_flat_start_batch to support large states_per_phoneme
1 parent 49516fd commit ac36db8

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

speechbrain/alignment/aligner.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,21 @@ def _get_flat_start_batch(self, lens_abs, phn_lens_abs, phns):
10421042
utter_phns = utter_phns[: phn_lens_abs[i]] # crop out zero padding
10431043
repeat_amt = int(lens_abs[i].item() / len(utter_phns))
10441044

1045+
# make sure repeat_amt is at least 1. (the code above
1046+
# may make repeat_amt==0 if self.states_per_phoneme is too large).
1047+
if repeat_amt == 0:
1048+
repeat_amt = 1
1049+
1050+
# repeat each phoneme in utter_phns by repeat_amt
10451051
utter_phns = utter_phns.repeat_interleave(repeat_amt)
10461052

1047-
# len(utter_phns) now may not equal lens[i]
1048-
# pad out with final phoneme to make lengths equal
1053+
# len(utter_phns) may be <, == or > lens_abs[i], so
1054+
# make sure len(utter_phns) == lens_abs[i]
1055+
utter_phns = utter_phns[: lens_abs[i]]
10491056
utter_phns = torch.nn.functional.pad(
10501057
utter_phns,
10511058
(0, int(lens_abs[i]) - len(utter_phns)),
1052-
value=utter_phns[-1],
1059+
value=utter_phns[-1], # pad out with final phoneme
10531060
)
10541061

10551062
flat_start_batch[i, : len(utter_phns)] = utter_phns

0 commit comments

Comments
 (0)