-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from cmusphinx/enhanced_alignment
New force-alignment API and two-pass alignment to get phone/state durations
- Loading branch information
Showing
46 changed files
with
1,519 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/python | ||
|
||
import os | ||
from pocketsphinx import Decoder | ||
import unittest | ||
|
||
DATADIR = os.path.join(os.path.dirname(__file__), "../../test/data") | ||
|
||
|
||
class TestAlignment(unittest.TestCase): | ||
def _run_decode(self, decoder, expect_fail=False): | ||
with open(os.path.join(DATADIR, "goforward.raw"), "rb") as fh: | ||
buf = fh.read() | ||
decoder.start_utt() | ||
decoder.process_raw(buf, no_search=False, full_utt=True) | ||
decoder.end_utt() | ||
|
||
def test_alignment(self): | ||
decoder = Decoder(lm=None) | ||
decoder.set_align_text("go forward ten meters") | ||
self._run_decode(decoder) | ||
words = [] | ||
for seg in decoder.seg(): | ||
if seg.word not in ("<s>", "</s>", "<sil>", "(NULL)"): | ||
words.append((seg.word, seg.start_frame, seg.end_frame)) | ||
print(words) | ||
decoder.set_alignment() | ||
self._run_decode(decoder) | ||
for word in decoder.get_alignment(): | ||
print(word.start, word.duration, word.score, word.name) | ||
for phone in word: | ||
print("\t", phone.start, phone.duration, phone.score, phone.name) | ||
for state in phone: | ||
print("\t\t", state.start, state.duration, state.score, state.name) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.