Somewhat fancy voice command recognition software
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Recognizer.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #This is part of Blather
  2. # -- this code is licensed GPLv3
  3. # Copyright 2013 Jezra
  4. import pygst
  5. pygst.require('0.10')
  6. import gst
  7. import os.path
  8. import gobject
  9. import sys
  10. #define some global variables
  11. this_dir = os.path.dirname( os.path.abspath(__file__) )
  12. class Recognizer(gobject.GObject):
  13. __gsignals__ = {
  14. 'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  15. }
  16. def __init__(self, language_file, dictionary_file, src = None):
  17. gobject.GObject.__init__(self)
  18. self.commands = {}
  19. if src:
  20. audio_src = 'alsasrc device="hw:%d,0"' % (src)
  21. else:
  22. audio_src = 'autoaudiosrc'
  23. #build the pipeline
  24. cmd = audio_src+' ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
  25. try:
  26. self.pipeline=gst.parse_launch( cmd )
  27. except Exception, e:
  28. print e.message
  29. print "You may need to install gstreamer0.10-pocketsphinx"
  30. raise e
  31. #get the Auto Speech Recognition piece
  32. asr=self.pipeline.get_by_name('asr')
  33. asr.connect('result', self.result)
  34. asr.set_property('lm', language_file)
  35. asr.set_property('dict', dictionary_file)
  36. asr.set_property('configured', True)
  37. #get the Voice Activity DEtectoR
  38. self.vad = self.pipeline.get_by_name('vad')
  39. self.vad.set_property('auto-threshold',True)
  40. def listen(self):
  41. self.pipeline.set_state(gst.STATE_PLAYING)
  42. def pause(self):
  43. self.vad.set_property('silent', True)
  44. self.pipeline.set_state(gst.STATE_PAUSED)
  45. def result(self, asr, text, uttid):
  46. #emit finished
  47. self.emit("finished", text)