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.2KB

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