示例#1
0
    def test_lm(self):
        ps = Pocketsphinx(dic='deps/pocketsphinx/test/data/defective.dic',
                          mmap=False)

        # Decoding with 'defective' dictionary
        ps.decode()
        self.assertEqual(ps.hypothesis(), '')

        # Switch to 'turtle' language model
        turtle_lm = 'deps/pocketsphinx/test/data/turtle.lm.bin'
        lm = NGramModel(ps.get_config(), ps.get_logmath(), turtle_lm)
        ps.set_lm('turtle', lm)
        ps.set_search('turtle')

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), '')

        # The word 'meters' isn't in the loaded dictionary
        # Let's add it manually
        ps.add_word('foobie', 'F UW B IY', False)
        ps.add_word('meters', 'M IY T ER Z', True)

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'foobie meters meters')
示例#2
0
    def test_lm(self):
        ps = Pocketsphinx(
            dic='deps/pocketsphinx/test/data/defective.dic',
            mmap=False
        )

        # Decoding with 'defective' dictionary
        ps.decode()
        self.assertEqual(ps.hypothesis(), '')

        # Switch to 'turtle' language model
        turtle_lm = 'deps/pocketsphinx/test/data/turtle.lm.bin'
        lm = NGramModel(ps.get_config(), ps.get_logmath(), turtle_lm)
        ps.set_lm('turtle', lm)
        ps.set_search('turtle')

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), '')

        # The word 'meters' isn't in the loaded dictionary
        # Let's add it manually
        ps.add_word('foobie', 'F UW B IY', False)
        ps.add_word('meters', 'M IY T ER Z', True)

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'foobie meters meters')
示例#3
0
class SpeechProcessor:
    def __init__(self, hmm='data/spanish/CIEMPIESS_Spanish_Models_581h/Models/modelo',
                       lm='data/spanish/CIEMPIESS_Spanish_Models_581h/Models/leng.lm.bin',
                       dict='data/spanish/CIEMPIESS_Spanish_Models_581h/Models/dicc.dic',
                       grammar='data/gramatica-tp2.gram', dataPath='tmp/'):
        self.data_path = dataPath
        config = {
            'hmm': hmm,
            'lm': lm,
            'dict': dict
        }
        #model_path = get_model_path()

        self.ps = Pocketsphinx(**config)
        
        # Switch to JSGF grammar
        jsgf = Jsgf(grammar)
        rule = jsgf.get_rule('tp2.grammar')
        fsg = jsgf.build_fsg(rule, self.ps.get_logmath(), 7.5)
        self.ps.set_fsg('tp2', fsg)
        self.ps.set_search('tp2')

        # Síntesis
        self.tts_authenticator = IAMAuthenticator('cq9_4YcCXxClw2AfgUhbokFktZ-xSRT4kcHS2akcZ05J')
        self.tts = TextToSpeechV1(authenticator=self.tts_authenticator)
        self.tts.set_service_url('https://stream.watsonplatform.net/text-to-speech/api')


    def sintetizar(self, outFileName, msg):
        if len(msg) > 0:
            with open(outFileName, 'wb') as audio_file:
                audio_file.write(
                    self.tts.synthesize(
                        msg,
                        voice='es-LA_SofiaV3Voice',
                        accept='audio/wav'
                    ).get_result().content)

    def reconocer(self, inFileName='audio.wav'):
        # Reconocimiento
        print(self.data_path)
        self.ps.decode(
            audio_file=os.path.join(self.data_path,inFileName),
            buffer_size=2048,
            no_search=False,
            full_utt=False
        )
        return self.ps.segments(), self.ps.best(count=3)
示例#4
0
    def test_jsgf(self):
        ps = Pocketsphinx(lm='deps/pocketsphinx/test/data/turtle.lm.bin',
                          dic='deps/pocketsphinx/test/data/turtle.dic')

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'go forward ten meters')

        # Switch to JSGF grammar
        jsgf = Jsgf('deps/pocketsphinx/test/data/goforward.gram')
        rule = jsgf.get_rule('goforward.move2')
        fsg = jsgf.build_fsg(rule, ps.get_logmath(), 7.5)
        ps.set_fsg('goforward', fsg)
        ps.set_search('goforward')

        # Decoding with 'goforward' grammar
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'go forward ten meters')
    def test_jsgf(self):
        ps = Pocketsphinx(
            lm='deps/pocketsphinx/test/data/turtle.lm.bin',
            dic='deps/pocketsphinx/test/data/turtle.dic'
        )

        # Decoding with 'turtle' language model
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'go forward ten meters')

        # Switch to JSGF grammar
        jsgf = Jsgf('deps/pocketsphinx/test/data/goforward.gram')
        rule = jsgf.get_rule('goforward.move2')
        fsg = jsgf.build_fsg(rule, ps.get_logmath(), 7.5)
        ps.set_fsg('goforward', fsg)
        ps.set_search('goforward')

        # Decoding with 'goforward' grammar
        ps.decode()
        self.assertEqual(ps.hypothesis(), 'go forward ten meters')