File: continuous_test.py

package info (click to toggle)
pocketsphinx 5.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,236 kB
  • sloc: ansic: 54,519; python: 2,438; sh: 566; cpp: 410; perl: 342; yacc: 93; lex: 50; makefile: 30
file content (38 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python

import os
from pocketsphinx import Decoder
import unittest

DATADIR = os.path.join(os.path.dirname(__file__), "../../test/data")


class TestContinuous(unittest.TestCase):
    def test_continuous(self):
        prev_cmn = (
            "41,-5.29,-0.12,5.09,2.48,-4.07,-1.37,-1.78,-5.08,-2.05,-6.45,-1.42,1.17"
        )
        decoder = Decoder(cmninit=prev_cmn)
        self.assertEqual(prev_cmn, decoder.get_cmn(False))

        with open(os.path.join(DATADIR, "goforward.raw"), "rb") as stream:
            decoder.start_utt()
            while True:
                buf = stream.read(1024)
                if buf:
                    decoder.process_raw(buf, False, False)
                    cmn = decoder.get_cmn(True)
                    self.assertNotEqual(prev_cmn, cmn)
                    prev_cmn = cmn
                else:
                    break
            decoder.end_utt()
            print("Result:", decoder.hyp().hypstr)
            self.assertEqual("go forward ten meters", decoder.hyp().hypstr)
            cmn = decoder.get_cmn(False)
            self.assertNotEqual(prev_cmn, cmn)
            prev_cmn = cmn


if __name__ == "__main__":
    unittest.main()