Somewhat fancy voice command recognition software
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

QtUI.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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
  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):
  15. gobject.GObject.__init__(self)
  16. #start by making our app
  17. self.app = QApplication(args)
  18. #make a window
  19. self.window = QMainWindow()
  20. #give the window a name
  21. self.window.setWindowTitle("BlatherQt")
  22. center = QWidget()
  23. self.window.setCentralWidget(center)
  24. layout = QVBoxLayout()
  25. center.setLayout(layout)
  26. #make a listen/stop button
  27. self.lsbutton = QPushButton("Listen")
  28. layout.addWidget(self.lsbutton)
  29. #make a continuous button
  30. self.ccheckbox = QCheckBox("Continuous Listen")
  31. layout.addWidget(self.ccheckbox)
  32. #connect the buttonsc
  33. self.lsbutton.clicked.connect(self.lsbutton_clicked)
  34. self.ccheckbox.clicked.connect(self.ccheckbox_clicked)
  35. #add a label to the UI to display the last command
  36. self.label = QLabel()
  37. layout.addWidget(self.label)
  38. def ccheckbox_clicked(self):
  39. checked = self.ccheckbox.isChecked()
  40. if checked:
  41. #disable lsbutton
  42. self.lsbutton.setEnabled(False)
  43. self.lsbutton_stopped()
  44. self.emit('command', "continuous_listen")
  45. else:
  46. self.lsbutton.setEnabled(True)
  47. self.emit('command', "continuous_stop")
  48. def lsbutton_stopped(self):
  49. self.lsbutton.setText("Listen")
  50. def lsbutton_clicked(self):
  51. val = self.lsbutton.text()
  52. if val == "Listen":
  53. self.emit("command", "listen")
  54. self.lsbutton.setText("Stop")
  55. #clear the label
  56. self.label.setText("")
  57. else:
  58. self.lsbutton_stopped()
  59. self.emit("command", "stop")
  60. def run(self):
  61. self.window.show()
  62. self.app.exec_()
  63. self.emit("command", "quit")
  64. def quit(self):
  65. pass
  66. def finished(self, text):
  67. print text
  68. #if the continuous isn't pressed
  69. if not self.ccheckbox.isChecked():
  70. self.lsbutton_stopped()
  71. self.label.setText(text)
  72. def quit(self):
  73. #sys.exit()
  74. pass