-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_gui_input_array.py
More file actions
93 lines (79 loc) · 2.81 KB
/
Copy pathmain_gui_input_array.py
File metadata and controls
93 lines (79 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Introduction to Algorithm course graphical interface design project input array page.
# 5 December 2021.
import sys
import speech_recognition as sr
from PyQt5.QtCore import pyqtSignal
# Written by Orhan Ozan Yildiz.
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from uiqt_array_input import Ui_MainWindow
class ArrayWindow(QMainWindow):
array_signal = pyqtSignal(list)
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.setWindowTitle('Enter Array')
self.ui.setupUi(self)
self.ui.add_array_btn.clicked.connect(self.addArray)
self.ui.mic_btn.clicked.connect(self.micro)
self.unsorted_array = []
self.voice = []
self.ui.add_array_btn.clicked.connect(self.close)
self.ui.clear_btn.clicked.connect(self.clear)
# %%%Speech Recognition
def micro(self):
r = sr.Recognizer()
microphoneValue = ""
with sr.Microphone() as source:
try:
# self.statusBar().showMessage('Start talking...')
audio = r.listen(source)
microphoneValue = (r.recognize_google(audio))
# self.statusBar().showMessage('Stop talking...')
if len(self.unsorted_array) == 0:
try:
microphoneValue = int(microphoneValue)
self.voice.append(microphoneValue)
self.ui.takearray_textedit.setText(str(self.voice))
self.take_Array()
except:
QMessageBox.warning(self, "ERROR", "Try again...")
else:
try:
self.take_Array()
microphoneValue = int(microphoneValue)
self.unsorted_array.append(microphoneValue)
self.ui.takearray_textedit.setText(str(self.unsorted_array))
except:
QMessageBox.warning(self, "ERROR", "Try again...")
except sr.UnknownValueError:
QMessageBox.information(self, "ERROR", "Sorry, Cant understand, Please say again..")
except sr.RequestError as e:
QMessageBox.information(self, "ERROR",
"Could not request results from Google Speech Recognition service; {0}".format(
e))
except sr.RequestError:
QMessageBox.information(self, "ERROR", "No Internet Connection...")
# %% Signal Connection
def addArray(self):
try:
self.take_Array()
self.array_signal.emit(self.unsorted_array)
self.close()
except ValueError:
QMessageBox.warning(self, "ERROR", "Enter the array in valid form...")
# %%Enter Array
def take_Array(self):
self.unsorted_array = self.ui.takearray_textedit.toPlainText() # .split(",")
self.unsorted_array = self.unsorted_array.strip("[")
self.unsorted_array = self.unsorted_array.strip("]")
self.unsorted_array = self.unsorted_array.split(",")
print(self.unsorted_array)
for i in range(len(self.unsorted_array)):
self.unsorted_array[i] = int(self.unsorted_array[i])
def clear(self):
self.ui.takearray_textedit.clear()
if __name__ == "__main__":
app = QApplication([])
window = ArrayWindow()
window.show()
sys.exit(app.exec_())