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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. self.pipeline=gst.parse_launch( cmd )
  25. #get the Auto Speech Recognition piece
  26. asr=self.pipeline.get_by_name('asr')
  27. asr.connect('result', self.result)
  28. asr.set_property('lm', language_file)
  29. asr.set_property('dict', dictionary_file)
  30. asr.set_property('configured', True)
  31. #get the Voice Activity DEtectoR
  32. self.vad = self.pipeline.get_by_name('vad')
  33. self.vad.set_property('auto-threshold',True)
  34. def listen(self):
  35. self.pipeline.set_state(gst.STATE_PLAYING)
  36. def pause(self):
  37. self.vad.set_property('silent', True)
  38. self.pipeline.set_state(gst.STATE_PAUSED)
  39. def result(self, asr, text, uttid):
  40. #emit finished
  41. self.emit("finished", text)