Somewhat fancy voice command recognition software
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Recognizer.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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):
  16. gobject.GObject.__init__(self)
  17. self.commands = {}
  18. #build the pipeline
  19. cmd = 'autoaudiosrc ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
  20. self.pipeline=gst.parse_launch( cmd )
  21. #get the Auto Speech Recognition piece
  22. asr=self.pipeline.get_by_name('asr')
  23. asr.connect('result', self.result)
  24. asr.set_property('lm', language_file)
  25. asr.set_property('dict', dictionary_file)
  26. asr.set_property('configured', True)
  27. #get the Voice Activity DEtectoR
  28. self.vad = self.pipeline.get_by_name('vad')
  29. self.vad.set_property('auto-threshold',True)
  30. def listen(self):
  31. self.pipeline.set_state(gst.STATE_PLAYING)
  32. def pause(self):
  33. self.vad.set_property('silent', True)
  34. self.pipeline.set_state(gst.STATE_PAUSED)
  35. def result(self, asr, text, uttid):
  36. #emit finished
  37. self.emit("finished", text)