Somewhat fancy voice command recognition software
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Recognizer.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #define some global variables
  10. this_dir = os.path.dirname( os.path.abspath(__file__) )
  11. class Recognizer(gobject.GObject):
  12. __gsignals__ = {
  13. 'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  14. }
  15. def __init__(self, language_file, dictionary_file, src = None):
  16. gobject.GObject.__init__(self)
  17. self.commands = {}
  18. if src:
  19. audio_src = 'alsasrc device="hw:%d,0"' % (src)
  20. else:
  21. audio_src = 'autoaudiosrc'
  22. #build the pipeline
  23. cmd = audio_src+' ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
  24. try:
  25. self.pipeline=gst.parse_launch( cmd )
  26. except Exception, e:
  27. print e.message
  28. print "You may need to install gstreamer0.10-pocketsphinx"
  29. #get the Auto Speech Recognition piece
  30. asr=self.pipeline.get_by_name('asr')
  31. asr.connect('result', self.result)
  32. asr.set_property('lm', language_file)
  33. asr.set_property('dict', dictionary_file)
  34. asr.set_property('configured', True)
  35. #get the Voice Activity DEtectoR
  36. self.vad = self.pipeline.get_by_name('vad')
  37. self.vad.set_property('auto-threshold',True)
  38. def listen(self):
  39. self.pipeline.set_state(gst.STATE_PLAYING)
  40. def pause(self):
  41. self.vad.set_property('silent', True)
  42. self.pipeline.set_state(gst.STATE_PAUSED)
  43. def result(self, asr, text, uttid):
  44. #emit finished
  45. self.emit("finished", text)