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.

QtUI.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  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 buttonsc
  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. def ccheckbox_clicked(self):
  41. checked = self.ccheckbox.isChecked()
  42. if checked:
  43. #disable lsbutton
  44. self.lsbutton.setEnabled(False)
  45. self.lsbutton_stopped()
  46. self.emit('command', "continuous_listen")
  47. else:
  48. self.lsbutton.setEnabled(True)
  49. self.emit('command', "continuous_stop")
  50. def lsbutton_stopped(self):
  51. self.lsbutton.setText("Listen")
  52. def lsbutton_clicked(self):
  53. val = self.lsbutton.text()
  54. if val == "Listen":
  55. self.emit("command", "listen")
  56. self.lsbutton.setText("Stop")
  57. #clear the label
  58. self.label.setText("")
  59. else:
  60. self.lsbutton_stopped()
  61. self.emit("command", "stop")
  62. def run(self):
  63. self.window.show()
  64. if self.continuous:
  65. self.ccheckbox.setCheckState(Qt.Checked)
  66. self.ccheckbox_clicked()
  67. self.app.exec_()
  68. self.emit("command", "quit")
  69. def finished(self, text):
  70. print text
  71. #if the continuous isn't pressed
  72. if not self.ccheckbox.isChecked():
  73. self.lsbutton_stopped()
  74. self.label.setText(text)
  75. def quit(self):
  76. #sys.exit()
  77. pass
  78. def set_icon(self, icon):
  79. self.window.setWindowIcon(QIcon(icon))