maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Speech Recognition (https://talk.maemo.org/showthread.php?t=86098)

tanrax 2012-08-14 20:21

Speech Recognition
 
I would make a python script to recognize certain words. For example, I say "dog" and print the number 1. What says "cat" and print the number 2. Is it possible in maemo? Can anyone leave me a code snippet?

MohammadAG 2012-08-14 21:22

Re: Speech Recognition
 
I'm not sure about Python, but search for PocketSphinx, it's an open source speech recognition engine, and it might have python bindings somewhere.

woody14619 2012-08-14 21:28

Re: Speech Recognition
 
You may want to also look at this thread.

tanrax 2012-08-15 07:51

Re: Speech Recognition
 
Thank you both. :) taixzo has happened to me this script. For now it does not work, but I'm on it. :rolleyes:

Code:

#!/usr/bin/python

import math
import gobject
import pygst
pygst.require('0.10')
gobject.threads_init()
import gst


class Example:
        def __init__(self):
                self.init_gst()


        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.set_property('configured', True)

                bus = self.pipeline.get_bus()
                bus.add_signal_watch()
                bus.connect('message::application', self.application_message)

                self.pipeline.set_state(gst.STATE_PAUSED)

        def asr_partial_result(self, asr, text, uttid):
                """Forward partial result signals on the bus to the main thread."""
                struct = gst.Structure('partial_result')
                struct.set_value('hyp', text)
                struct.set_value('uttid', uttid)
                asr.post_message(gst.message_new_application(asr, struct))

        def asr_result(self, asr, text, uttid):
                """Forward result signals on the bus to the main thread."""
                struct = gst.Structure('result')
                struct.set_value('hyp', text)
                struct.set_value('uttid', uttid)
                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':
                        self.final_result(msg.structure['hyp'], msg.structure['uttid'])
                        self.pipeline.set_state(gst.STATE_PAUSED)
                       
        def partial_result(self, hyp, uttid):
                """Delete any previous selection, insert text and select it."""
                # All this stuff appears as one single action
                print "Partial Result:", hyp
               
        def final_result(self, hyp, uttid):
          """Insert the final result."""
          # All this stuff appears as one single action
          if hyp in ('start', 'power', 'red', 'green', 'yellow', 'blue')
                  print "Final Result:", hyp
          else:
                  print "Not a recognized word."

if __name__=='__main__':

        app = Example()
        loop = gobject.MainLoop()
        gobject.threads_init()
        loop.run()



All times are GMT. The time now is 16:45.

vBulletin® Version 3.8.8