Somewhat fancy voice command recognition software
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

GtkUI.py 2.0KB

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