Somewhat fancy voice command recognition software
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #This is part of Blather
  2. # -- this code is licensed GPLv3
  3. # Copyright 2013 Jezra
  4. import sys
  5. import gobject
  6. #Gtk
  7. import pygtk
  8. import gtk
  9. class UI(gobject.GObject):
  10. __gsignals__ = {
  11. 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  12. }
  13. def __init__(self,args):
  14. gobject.GObject.__init__(self)
  15. #make a window
  16. self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  17. self.window.connect("delete_event", self.delete_event)
  18. #give the window a name
  19. self.window.set_title("BlatherGtk")
  20. layout = gtk.VBox()
  21. self.window.add(layout)
  22. #make a listen/stop button
  23. self.lsbutton = gtk.Button("Listen")
  24. layout.add(self.lsbutton)
  25. #make a continuous button
  26. self.ccheckbox = gtk.CheckButton("Continuous Listen")
  27. layout.add(self.ccheckbox)
  28. #connect the buttonsc
  29. self.lsbutton.connect("clicked",self.lsbutton_clicked)
  30. self.ccheckbox.connect("clicked",self.ccheckbox_clicked)
  31. #add a label to the UI to display the last command
  32. self.label = gtk.Label()
  33. layout.add(self.label)
  34. def ccheckbox_clicked(self, widget):
  35. checked = self.ccheckbox.get_active()
  36. self.lsbutton.set_sensitive(not checked)
  37. if checked:
  38. self.lsbutton_stopped()
  39. self.emit('command', "continuous_listen")
  40. else:
  41. self.emit('command', "continuous_stop")
  42. def lsbutton_stopped(self):
  43. self.lsbutton.set_label("Listen")
  44. def lsbutton_clicked(self, button):
  45. val = self.lsbutton.get_label()
  46. if val == "Listen":
  47. self.emit("command", "listen")
  48. self.lsbutton.set_label("Stop")
  49. #clear the label
  50. self.label.set_text("")
  51. else:
  52. self.lsbutton_stopped()
  53. self.emit("command", "stop")
  54. def run(self):
  55. self.window.show_all()
  56. def quit(self):
  57. pass
  58. def delete_event(self, x, y ):
  59. self.emit("command", "quit")
  60. def finished(self, text):
  61. print text
  62. #if the continuous isn't pressed
  63. if not self.ccheckbox.get_active():
  64. self.lsbutton_stopped()
  65. self.label.set_text(text)