Somewhat fancy voice command recognition software
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. self.window.set_resizable(False)
  21. layout = gtk.VBox()
  22. self.window.add(layout)
  23. #make a listen/stop button
  24. self.lsbutton = gtk.Button("Listen")
  25. layout.add(self.lsbutton)
  26. #make a continuous button
  27. self.ccheckbox = gtk.CheckButton("Continuous Listen")
  28. layout.add(self.ccheckbox)
  29. #connect the buttonsc
  30. self.lsbutton.connect("clicked",self.lsbutton_clicked)
  31. self.ccheckbox.connect("clicked",self.ccheckbox_clicked)
  32. #add a label to the UI to display the last command
  33. self.label = gtk.Label()
  34. layout.add(self.label)
  35. def ccheckbox_clicked(self, widget):
  36. checked = self.ccheckbox.get_active()
  37. self.lsbutton.set_sensitive(not checked)
  38. if checked:
  39. self.lsbutton_stopped()
  40. self.emit('command', "continuous_listen")
  41. else:
  42. self.emit('command', "continuous_stop")
  43. def lsbutton_stopped(self):
  44. self.lsbutton.set_label("Listen")
  45. def lsbutton_clicked(self, button):
  46. val = self.lsbutton.get_label()
  47. if val == "Listen":
  48. self.emit("command", "listen")
  49. self.lsbutton.set_label("Stop")
  50. #clear the label
  51. self.label.set_text("")
  52. else:
  53. self.lsbutton_stopped()
  54. self.emit("command", "stop")
  55. def run(self):
  56. self.window.show_all()
  57. def quit(self):
  58. pass
  59. def delete_event(self, x, y ):
  60. self.emit("command", "quit")
  61. def finished(self, text):
  62. print text
  63. #if the continuous isn't pressed
  64. if not self.ccheckbox.get_active():
  65. self.lsbutton_stopped()
  66. self.label.set_text(text)