summary refs log tree commit diff
path: root/recognizer.py
diff options
context:
space:
mode:
authorClayton G. Hobbs <clay@lakeserv.net>2015-12-26 22:43:12 -0500
committerClayton G. Hobbs <clay@lakeserv.net>2015-12-26 22:43:12 -0500
commit2a641364bf8fc3cc4069d2d2c42b75241e6dc3f2 (patch)
treeeed87314f415db72ce65ecc81baa9ef3a0a79548 /recognizer.py
parenta6e27df2ccf8a22d76b2ff795dee2f86f52b3970 (diff)
Removed QT interface, renamed interfaces to Kaylee
I'm a GTK man myself.  I don't know if I have Python QT bindings
installed on any of my computers.  It follows then that I would not
maintain the QT interface well, let alone use it at all.  It has
therefore been removed to avoid having someone try to use it only to
find that it's broken.
Diffstat (limited to 'recognizer.py')
-rwxr-xr-xrecognizer.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/recognizer.py b/recognizer.py
new file mode 100755
index 0000000..038d4cf
--- /dev/null
+++ b/recognizer.py
@@ -0,0 +1,66 @@
+# This is part of Kaylee
+# -- this code is licensed GPLv3
+# Copyright 2013 Jezra
+# Copyright 2015 Clayton G. Hobbs
+
+import gi
+gi.require_version('Gst', '1.0')
+from gi.repository import GObject, Gst
+GObject.threads_init()
+Gst.init(None)
+import os.path
+import sys
+
+# Define some global variables
+this_dir = os.path.dirname( os.path.abspath(__file__) )
+
+
+class Recognizer(GObject.GObject):
+    __gsignals__ = {
+        'finished' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
+    }
+
+    def __init__(self, language_file, dictionary_file, src = None):
+        GObject.GObject.__init__(self)
+        self.commands = {}
+        if src:
+            audio_src = 'alsasrc device="hw:%d,0"' % (src)
+        else:
+            audio_src = 'autoaudiosrc'
+
+        # Build the pipeline
+        cmd = audio_src+' ! audioconvert ! audioresample ! pocketsphinx name=asr ! appsink sync=false'
+        try:
+            self.pipeline=Gst.parse_launch( cmd )
+        except Exception, e:
+            print e.message
+            print "You may need to install gstreamer1.0-pocketsphinx"
+            raise e
+
+        bus = self.pipeline.get_bus()
+        bus.add_signal_watch()
+
+        # Get the Auto Speech Recognition piece
+        asr=self.pipeline.get_by_name('asr')
+        bus.connect('message::element', self.result)
+        asr.set_property('lm', language_file)
+        asr.set_property('dict', dictionary_file)
+        asr.set_property('configured', True)
+
+    def listen(self):
+        self.pipeline.set_state(Gst.State.PLAYING)
+
+    def pause(self):
+        self.pipeline.set_state(Gst.State.PAUSED)
+
+    def result(self, bus, msg):
+        msg_struct = msg.get_structure()
+        # Ignore messages that aren't from pocketsphinx
+        msgtype = msg_struct.get_name()
+        if msgtype != 'pocketsphinx':
+            return
+
+        # If we have a final command, send it for processing
+        command = msg_struct.get_string('hypothesis')
+        if command != '' and msg_struct.get_boolean('final')[1]:
+	    self.emit("finished", command)