When I try to run speech recognition in pyqt5 program is crashed. Sr's code is at the another script file. I import it to pyqt5 script. I connected button with sr function. When I press the button sr work but crashs both.
PyQt5 Code:
import sys
from PyQt5 import QtWidgets,QtGui
from Speech_Recognition import Voice
def Gui():
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.setGeometry(200,200,150,150)
button1 = QtWidgets.QPushButton(window)
button1.setText("Start")
button1.clicked.connect(Voice)
window.show()
sys.exit(app.exec())
Gui()
Speech Recognition
import speech_recognition as sr
text = ""
def Voice():
r = sr.Recognizer()
m = sr.Microphone()
while True:
print("Say somethig!")
with m as source:
audio = r.listen(source)
print("Got it! Now to recognize it...")
try:
value = r.recognize_google(audio)
text = value
print("You said: {}".format(text))
except sr.UnknownValueError:
print("Oops")