Somewhat fancy voice command recognition software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QtUI.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #This is part of Blather
  2. # -- this code is licensed GPLv3
  3. # Copyright 2013 Jezra
  4. import sys
  5. import gobject
  6. # Qt stuff
  7. from PySide.QtCore import Signal, Qt
  8. from PySide.QtGui import QApplication, QWidget, QMainWindow, QVBoxLayout
  9. from PySide.QtGui import QLabel, QPushButton, QCheckBox, QIcon, QAction
  10. class UI(gobject.GObject):
  11. __gsignals__ = {
  12. 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  13. }
  14. def __init__(self,args,continuous):
  15. self.continuous = continuous
  16. gobject.GObject.__init__(self)
  17. #start by making our app
  18. self.app = QApplication(args)
  19. #make a window
  20. self.window = QMainWindow()
  21. #give the window a name
  22. self.window.setWindowTitle("BlatherQt")
  23. self.window.setMaximumSize(400,200)
  24. center = QWidget()
  25. self.window.setCentralWidget(center)
  26. layout = QVBoxLayout()
  27. center.setLayout(layout)
  28. #make a listen/stop button
  29. self.lsbutton = QPushButton("Listen")
  30. layout.addWidget(self.lsbutton)
  31. #make a continuous button
  32. self.ccheckbox = QCheckBox("Continuous Listen")
  33. layout.addWidget(self.ccheckbox)
  34. #connect the buttons
  35. self.lsbutton.clicked.connect(self.lsbutton_clicked)
  36. self.ccheckbox.clicked.connect(self.ccheckbox_clicked)
  37. #add a label to the UI to display the last command
  38. self.label = QLabel()
  39. layout.addWidget(self.label)
  40. #add the actions for quiting
  41. quit_action = QAction(self.window)
  42. quit_action.setShortcut('Ctrl+Q')
  43. quit_action.triggered.connect(self.accel_quit)
  44. self.window.addAction(quit_action)
  45. def accel_quit(self):
  46. #emit the quit
  47. self.emit("command", "quit")
  48. def ccheckbox_clicked(self):
  49. checked = self.ccheckbox.isChecked()
  50. if checked:
  51. #disable lsbutton
  52. self.lsbutton.setEnabled(False)
  53. self.lsbutton_stopped()
  54. self.emit('command', "continuous_listen")
  55. else:
  56. self.lsbutton.setEnabled(True)
  57. self.emit('command', "continuous_stop")
  58. def lsbutton_stopped(self):
  59. self.lsbutton.setText("Listen")
  60. def lsbutton_clicked(self):
  61. val = self.lsbutton.text()
  62. if val == "Listen":
  63. self.emit("command", "listen")
  64. self.lsbutton.setText("Stop")
  65. #clear the label
  66. self.label.setText("")
  67. else:
  68. self.lsbutton_stopped()
  69. self.emit("command", "stop")
  70. def run(self):
  71. self.window.show()
  72. if self.continuous:
  73. self.ccheckbox.setCheckState(Qt.Checked)
  74. self.ccheckbox_clicked()
  75. self.app.exec_()
  76. self.emit("command", "quit")
  77. def finished(self, text):
  78. print text
  79. #if the continuous isn't pressed
  80. if not self.ccheckbox.isChecked():
  81. self.lsbutton_stopped()
  82. self.label.setText(text)
  83. def set_icon(self, icon):
  84. self.window.setWindowIcon(QIcon(icon))