MontrealCorpusTools / Montreal-Forced-Aligner

Command line utility for forced alignment using Kaldi
https://montrealcorpustools.github.io/Montreal-Forced-Aligner/
MIT License
1.26k stars 242 forks source link

fixed an item-lost bug when exporting to textgrid #814

Closed fncokg closed 1 month ago

fncokg commented 1 month ago

There is a item-lost bug in the previous version, which will make every file to lose its first phone and word item in the exported textgrid file.

Problem

In function construct_textgrid_output of file textgrid.py, the while True loop ends with this:

https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/76c46a197f7f7d827f33c36bfe0088568294ecc6/montreal_forced_aligner/textgrid.py#L420-L422

These codes empty the three lists, while they are not empty because of these lines:

https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/76c46a197f7f7d827f33c36bfe0088568294ecc6/montreal_forced_aligner/textgrid.py#L377

https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/76c46a197f7f7d827f33c36bfe0088568294ecc6/montreal_forced_aligner/textgrid.py#L393

https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/76c46a197f7f7d827f33c36bfe0088568294ecc6/montreal_forced_aligner/textgrid.py#L406

Emptying them at the ending of a loop will cause a direct data discard.

Solution

I removed the three lines first, and to avoid the loop becomes an infinite loop, in this if block:

https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/76c46a197f7f7d827f33c36bfe0088568294ecc6/montreal_forced_aligner/textgrid.py#L383-L387

I added a:

phone_data = []

These codes were tested and worked well now.