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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python2
  2. import pygst
  3. pygst.require('0.10')
  4. import gst
  5. import os.path
  6. import gobject
  7. #define some global variables
  8. this_dir = os.path.dirname( os.path.abspath(__file__) )
  9. class Recognizer(gobject.GObject):
  10. __gsignals__ = {
  11. 'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  12. }
  13. def __init__(self, language_file, dictionary_file):
  14. gobject.GObject.__init__(self)
  15. self.commands = {}
  16. #build the pipeline
  17. cmd = 'autoaudiosrc ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
  18. self.pipeline=gst.parse_launch( cmd )
  19. #get the Auto Speech Recognition piece
  20. asr=self.pipeline.get_by_name('asr')
  21. asr.connect('result', self.result)
  22. asr.set_property('lm', language_file)
  23. asr.set_property('dict', dictionary_file)
  24. asr.set_property('configured', True)
  25. #get the Voice Activity DEtectoR
  26. self.vad = self.pipeline.get_by_name('vad')
  27. self.vad.set_property('auto-threshold',True)
  28. def listen(self):
  29. self.pipeline.set_state(gst.STATE_PLAYING)
  30. def pause(self):
  31. self.vad.set_property('silent', True)
  32. self.pipeline.set_state(gst.STATE_PAUSED)
  33. def result(self, asr, text, uttid):
  34. #emit finished
  35. self.emit("finished", text)