示例#1
0
    def test_misaligned(self):
        misaligned_pause = Pause('', 0.50, 0.25)
        assert_true(misaligned_pause.misaligned)

        phone_sil = Phone('SIL')
        misaligned_pause._phones = [phone_sil]
        assert_true(misaligned_pause.misaligned)
示例#2
0
    def test_multiple_medial_pauses(self):
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.0),
            Pause('<SIL>', 1.0, 1.42),
            Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words))

        assert_equal(len(utterances), 2)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
            assert_equal(words[i].orthography, word.orthography)
            assert_equal(words[i].phonemic, word.phonemic)
            assert_equal(words[i].phonetic, word.phonetic)

        for i, word in enumerate(utterances[1], 7):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
            assert_equal(words[i].orthography, word.orthography)
            assert_equal(words[i].phonemic, word.phonemic)
            assert_equal(words[i].phonetic, word.phonetic)
示例#3
0
    def test_speech_rate_pause_at_beg_and_middle(self):
        words = [Pause(beg=0, end=0.39)] + self.words[2:]
        words[2] = Pause(beg=0.55, end=0.73)
        utt = Utterance(words)

        # raises
        assert_raises(ValueError, utt.speech_rate)
        assert_raises(ValueError, utt.speech_rate, False, 'raises')

        # zero
        assert_equal(utt.speech_rate(no_syllables='zero'), 2.4)

        # squeeze
        assert_equal(utt.speech_rate(no_syllables='squeeze'), 3 / 0.86)
示例#4
0
    def test_speech_rate_pause_at_end_and_middle(self):
        words = self.words + [Pause(beg=1.25, end=1.50)]
        words[-3] = Pause(beg=0.73, end=0.80)

        utt = Utterance(words)

        # raises
        assert_raises(ValueError, utt.speech_rate)
        assert_raises(ValueError, utt.speech_rate, False, 'raises')

        # zero
        assert_equal(utt.speech_rate(no_syllables='zero'), 8 / 3)

        # squeeze
        assert_equal(utt.speech_rate(no_syllables='squeeze'), 4 / 1.25)
示例#5
0
    def test_strip_pause_only(self):
        pause = Pause(beg=1.25, end=1.95)
        utt_strip = Utterance([pause])

        utt_strip.strip()

        assert_equal(utt_strip.words(), [])
示例#6
0
    def test_sep_arg(self):
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.0),
            Word('mat', 1.0, 1.28, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words, sep=0.08))

        assert_equal(len(utterances), 2)
        assert_equal(len(utterances[0]), 5)
        assert_equal(len(utterances[1]), 1)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
            assert_equal(words[i].orthography, word.orthography)
            assert_equal(words[i].phonemic, word.phonemic)
            assert_equal(words[i].phonetic, word.phonetic)

        assert_equal(words[6].beg, utterances[1][0].beg)
        assert_equal(words[6].end, utterances[1][0].end)
        assert_equal(words[6].orthography, utterances[1][0].orthography)
        assert_equal(words[6].phonemic, utterances[1][0].phonemic)
        assert_equal(words[6].phonetic, utterances[1][0].phonetic)
示例#7
0
    def test_strip_beg_pause(self):
        pause = Pause(beg=0, end=0.55)
        utt_strip = Utterance([pause] + self.words[3:])

        utt_strip.strip()

        assert_not_in(pause, utt_strip)
        assert_equal(utt_strip.words(), self.words[3:])
示例#8
0
    def test_strip_end_pause(self):
        pause = Pause(beg=1.25, end=1.85)
        utt_strip = Utterance(self.words + [pause])

        utt_strip.strip()

        assert_not_in(pause, utt_strip)
        assert_equal(utt_strip.words(), self.words)
示例#9
0
    def test_multiple_short_medial_pauses(self):
        words = self.words[:]
        words[3:] = [
            Pause('<VOCNOISE>', 0.59, 0.65),
            Word('on', 0.65, 0.77, ['aa', 'n'], ['aa', 'n']), self.words[4],
            Pause('<SIL>', 0.91, 1.35),
            Word('mat', 1.35, 1.63, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words))

        assert_equal(len(utterances), 1)
        assert_equal(words[3].entry, utterances[0][3].entry)
        assert_equal(words[6].entry, utterances[0][6].entry)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#10
0
    def test_initial_pause_no_strip(self):
        initial_pause = Pause('<SIL>', 0.0, 0.05)
        words = [initial_pause] + self.words

        utterances = list(words_to_utterances(words, strip_pauses=False))

        assert_equal(len(utterances), 1)
        assert_equal(len(utterances[0]), 7)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#11
0
    def test_multiple_medial_pauses_no_strip(self):
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.0),
            Pause('<SIL>', 1.0, 1.42),
            Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words, strip_pauses=False))

        assert_equal(len(utterances), 2)
        assert_equal(len(utterances[0]), 7)
        assert_equal(len(utterances[1]), 1)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)

        for i, word in enumerate(utterances[1], 7):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#12
0
    def test_strip_end_multiple(self):
        pause = Pause(beg=1.25, end=1.95)
        zero = Word('', 1.95, 1.95)
        utt_strip = Utterance()
        utt_strip._words = self.words + [pause, zero]

        utt_strip.strip()

        for entry in {pause, zero}:
            assert_not_in(entry, utt_strip)

        assert_equal(utt_strip.words(), self.words)
示例#13
0
    def test_final_pause_no_strip(self):
        final_pause = Pause('<SIL>', 1.19, 1.25)
        words = self.words + [final_pause]

        utterances = list(words_to_utterances(words, strip_pauses=False))

        assert_equal(len(utterances), 1)
        assert_equal(len(utterances[0]), 7)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#14
0
    def test_strip_beg_multiple(self):
        pause = Pause(beg=0, end=0.39)
        zero = Word('', 0.39, 0.39)
        utt_strip = Utterance()
        utt_strip._words = [pause, zero] + self.words[2:]

        utt_strip.strip()

        for entry in {pause, zero}:
            assert_not_in(entry, utt_strip)

        assert_equal(utt_strip.words(), self.words[2:])
示例#15
0
    def test_speech_rate_pause_at_end(self):
        utt = Utterance(self.words)
        utt.append(Pause(beg=1.25, end=1.50))

        # raises
        assert_raises(ValueError, utt.speech_rate)
        assert_raises(ValueError, utt.speech_rate, False, 'raises')

        # zero
        assert_equal(utt.speech_rate(no_syllables='zero'), 10 / 3)

        # squeeze
        assert_equal(utt.speech_rate(no_syllables='squeeze'), 4.0)
示例#16
0
    def test_short_medial_pause(self):
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.0),
            Word('mat', 1.0, 1.28, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words))

        assert_equal(len(utterances), 1)
        assert_equal(words[5].entry, utterances[0][5].entry)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#17
0
    def test_medial_pause_no_strip(self):
        # insert a pause into a copy of the word list
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.42),
            Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words, strip_pauses=False))

        assert_equal(len(utterances), 2)
        assert_equal(len(utterances[0]), 6)
        assert_equal(len(utterances[1]), 1)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)
示例#18
0
    def test_medial_pause(self):
        # insert a pause into a copy of the word list
        words = self.words[:]
        words[5:] = [
            Pause('<SIL>', 0.91, 1.42),
            Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't'])
        ]

        utterances = list(words_to_utterances(words))

        assert_equal(len(utterances), 2)
        assert_equal(len(utterances[0]), 5)
        assert_equal(len(utterances[1]), 1)

        for i, word in enumerate(utterances[0]):
            assert_equal(words[i].beg, word.beg)
            assert_equal(words[i].end, word.end)

        assert_equal(words[6].beg, utterances[1][0].beg)
        assert_equal(words[6].end, utterances[1][0].end)
        assert_equal(words[6].orthography, utterances[1][0].orthography)
        assert_equal(words[6].phonemic, utterances[1][0].phonemic)
        assert_equal(words[6].phonetic, utterances[1][0].phonetic)
示例#19
0
    def test_speech_rate_pause_at_end_raise(self):
        utt = Utterance(self.words)
        utt.append(Pause(beg=1.25, end=1.50))

        assert_raises(ValueError, utt.speech_rate)
示例#20
0
    def test_speech_rate_pause_at_end_ignore(self):
        utt = Utterance(self.words)
        utt.append(Pause(beg=1.25, end=1.50))

        assert_equal(utt.speech_rate(ignore_missing_syllables=True), 10 / 3)
示例#21
0
    def test_final_pause(self):
        final_pause = Pause('<SIL>', 1.19, 1.25)
        utterances = list(words_to_utterances(self.words + [final_pause]))

        yield self.check_expected, utterances
示例#22
0
    def test_initial_pause(self):
        initial_pause = Pause('<SIL>', 0.0, 0.05)
        utterances = list(words_to_utterances([initial_pause] + self.words))

        yield self.check_expected, utterances
示例#23
0
 def setup(self):
     self.pause = Pause('<SIL>', 0.0, 0.05)
示例#24
0
    def test_speech_rate_pause_at_beg_and_middle_ignore(self):
        words = [Pause(beg=0, end=0.39)] + self.words[2:]
        words[2] = Pause(beg=0.55, end=0.73)
        utt = Utterance(words)

        assert_equal(utt.speech_rate(ignore_missing_syllables=True), 2.4)
示例#25
0
    def test_speech_rate_pause_at_end_and_middle_ignore(self):
        words = self.words + [Pause(beg=1.25, end=1.50)]
        words[-3] = Pause(beg=0.73, end=0.80)

        utt = Utterance(words)
        assert_equal(utt.speech_rate(ignore_missing_syllables=True), 8 / 3)
示例#26
0
    def test_str_pause(self):
        utt = Utterance(self.words)
        utt.append(Pause('VOCNOISE', 1.25, 1.50))

        assert_equal(str(utt), '<Utterance "the cat is on the mat VOCNOISE">')
示例#27
0
    def test_empty_pause(self):
        empty_pause = Pause()

        assert_is_none(empty_pause.entry)
        assert_is_none(empty_pause.beg)
        assert_is_none(empty_pause.end)
示例#28
0
    def test_speech_rate_pause_at_end_and_middle_raise(self):
        words = self.words + [Pause(beg=1.25, end=1.50)]
        words[-3] = Pause(beg=0.73, end=0.80)
        utt = Utterance(words)

        assert_raises(ValueError, utt.speech_rate)
示例#29
0
 def test_misaligned_zero(self):
     zero_pause = Pause('', 0.40, 0.40)
     assert_false(zero_pause.misaligned)
示例#30
0
    def test_speech_rate_pause_at_beg_and_middle_raise(self):
        words = [Pause(beg=0, end=0.39)] + self.words[2:]
        words[2] = Pause(beg=0.55, end=0.73)
        utt = Utterance(words)

        assert_raises(ValueError, utt.speech_rate)