-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecialHandlers.py
135 lines (119 loc) · 3.64 KB
/
specialHandlers.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from pathlib import Path
from voice import listener
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('rate', 130)
#from implementMain import completeListener
def handleSrc():
while True:
print(f'jony: speak src value')
spoken = listener()
# file are with different extension like .jpg,jpeg,mp4 we have to find appropriate file
fileToOpen = completeFile(spoken)
if fileToOpen:
return fileToOpen
def handleTable():
row = 1
rowData = []
while True:
print(f'Table row {row}')
rowInner = listenTableData(row)
intermidiateRow = {
"tag": 'tr',
"innerElement": rowInner
}
rowData.append(intermidiateRow)
print(rowData)
engine.say('Want to add more rows say yes to add it')
engine.runAndWait()
print(f"want to add more rows? 'Yes' to continue")
openion = listener()
if "yes" not in openion.lower():
return rowData
row = row+1
def listenTableData(row):
tag = 'td'
values = []
if row == 1:
tag = 'th'
# now to listen data in a table row we loop
while True:
engine.say('Give me a data.')
engine.runAndWait()
print(f"speak {tag} data")
spoken = listener()
data = {
"tag": tag,
"value": spoken
}
values.append(data)
engine.say('Is there more table data say yes to have it')
engine.runAndWait()
print(f"more {tag}? speak 'Yes' to continue")
openion = listener()
if "yes" not in openion.lower():
return values
# this handle specially ordered or unordered list
def handleList():
listNo = 1
listCollection = []
while True:
engine.say('Give me a list value')
engine.runAndWait()
print(f"{listNo} list value")
value = listener()
list = {
"tag": "li",
"value": value
}
listCollection.append(list)
print(f'updatedli: {listCollection} ')
engine.say('Do you want to add more sir please say yes to continue')
engine.runAndWait()
print(f"want to add more? 'Yes' to continue")
openion = listener()
if "yes" not in openion.lower():
return listCollection
listNo = listNo+1
# select tag handler
def handleSelect():
optionNo = 1
options = []
while True:
engine.say('Please give me an option')
engine.runAndWait()
print(f"speak option {optionNo}")
value = listener()
option = {
"tag": 'option',
"value": value
}
options.append(option)
print(options)
engine.say('Is there more option sir say yes to add more')
engine.runAndWait()
print(f"is their more option?.. say yes to add more")
openion = listener()
if 'yes' not in openion.lower():
return options
optionNo += 1
# this function looks for appropriate match for spekon file
def completeFile(spoken):
dataFolder = Path(
'F:\FinalYear_Project\imgAndVedio')
extension = ['jpeg', 'jpg', 'png', 'mp4', 'mp3']
print(spoken)
if spoken.endswith('.*'):
possible = dataFolder/spoken
if possible.exists():
return possible
else:
for complete in extension:
imagename=(spoken+'.'+complete)
possible = dataFolder/(spoken+'.'+complete)
if possible.exists():
return imagename
engine.say('Provided File doesnot exist sir')
engine.runAndWait()
print("File doesn't exist")
return None