class textProssesThread(QThread):
def __init__(self,audio):
super().__init__()
self.audio = audio
def run(self):
text = r.recognize_google(self.audio)
mainWin.pybutton.setText(text)
class listenThread(QThread):
def __init__(self):
super().__init__()
def run(self) -> None:
with sr.Microphone() as source:
audio = r.listen(source)
a = textProssesThread(audio)
a.start()
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.pybutton = QPushButton('Click me', self)
self.pybutton.clicked.connect(self.clickMethod)
self.pybutton.resize(100, 32)
self.pybutton.move(50, 50)
self.show()
def clickMethod(self):
a = listenThread()
a.start()
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
sys.exit(app.exec_())
若我调用此函数,程序将崩溃,但若我在调试模式下调用,代码将正常工作。这里怎么了?我应该如何制作这个代码
为我工作:
相关问题 更多 >
编程相关推荐