class Saera: def __init__(self): self.result_score = False
def init_gst(self): """Initialize the speech components""" self.pipeline = gst.parse_launch('pulsesrc ! audioconvert ! audioresample ' + '! vader name=vad auto-threshold=true ' + '! pocketsphinx name=asr ! fakesink') asr = self.pipeline.get_by_name('asr') asr.connect('partial_result', self.asr_partial_result) asr.connect('result', self.asr_result) asr.connect('result_score', self.asr_result_score) asr.set_property('configured', True)
def asr_result_score(self, asr, text, score): """Forward result signals on the bus to the main thread.""" struct = gst.Structure('result_score') struct.set_value('hyp', text) struct.set_value('score', score) asr.post_message(gst.message_new_application(asr, struct))
def application_message(self, bus, msg): """Receive application messages from the bus.""" msgtype = msg.structure.get_name() if msgtype == 'partial_result': self.partial_result(msg.structure['hyp'], msg.structure['uttid']) elif msgtype == 'result_score': self.result_score = True self.final_result_score(msg.structure['hyp'], msg.structure['score']) # self.pipeline.set_state(gst.STATE_PAUSED) elif msgtype == 'result' and self.result_score == False: self.final_result(msg.structure['hyp'], msg.structure['uttid'])
def final_result_score(self, hyp, score): """Insert the final result.""" # All this stuff appears as one single action print "Final Result: ", hyp, " score: ", score if int(score) > -18500000: self.run_saera(None, "speech-event", hyp)