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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. self.set_icon_active()
  56. else:
  57. self.lsbutton.setEnabled(True)
  58. self.emit('command', "continuous_stop")
  59. self.set_icon_inactive()
  60. def lsbutton_stopped(self):
  61. self.lsbutton.setText("Listen")
  62. def lsbutton_clicked(self):
  63. val = self.lsbutton.text()
  64. if val == "Listen":
  65. self.emit("command", "listen")
  66. self.lsbutton.setText("Stop")
  67. #clear the label
  68. self.label.setText("")
  69. self.set_icon_active()
  70. else:
  71. self.lsbutton_stopped()
  72. self.emit("command", "stop")
  73. self.set_icon_inactive()
  74. def run(self):
  75. self.set_icon_inactive()
  76. self.window.show()
  77. if self.continuous:
  78. self.set_icon_active()
  79. self.ccheckbox.setCheckState(Qt.Checked)
  80. self.ccheckbox_clicked()
  81. self.app.exec_()
  82. self.emit("command", "quit")
  83. def finished(self, text):
  84. print text
  85. #if the continuous isn't pressed
  86. if not self.ccheckbox.isChecked():
  87. self.lsbutton_stopped()
  88. self.label.setText(text)
  89. def set_icon(self, icon):
  90. self.window.setWindowIcon(QIcon(icon))
  91. def set_icon_active_asset(self, i):
  92. self.icon_active = i
  93. def set_icon_inactive_asset(self, i):
  94. self.icon_inactive = i
  95. def set_icon_active(self):
  96. self.window.setWindowIcon(QIcon(self.icon_active))
  97. def set_icon_inactive(self):
  98. self.window.setWindowIcon(QIcon(self.icon_inactive))