Somewhat fancy voice command recognition software
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GtkUI.py 1.8KB

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