-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
141 lines (134 loc) · 5.67 KB
/
Main.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
136
137
138
139
140
141
import VoiceRecognition as VR
import VoiceOutput as V_OP
import VolumeControl as VC
import BrightnessControl as BC
import SpeechCommandDataset as DS
import UsabilityHelpers as UH
import time as t
#driver program to run this project/application
FlagForServiceStart = False
UH.DesignPrinter()
V_OP.speech("Welcome to system volume and brightness controller using voice commands, 'A voice assistant for controlling system volume and brightness'.")
V_OP.speech("Say 'start' to start services to listen to your voice commands, then start giving your voice commands to make adjustments with the system volume and brightness.")
V_OP.speech("You can ask 'current volume' or 'current brightness' to know the current volume or brightness level.")
V_OP.speech("You can say 'stop' to pause the services for a while, and you can say 'exit' to terminate this program.")
UH.DesignPrinter()
V_OP.speech("Waiting for voice command to start services.")
while(True):
text = VR.SpeechToText()
if(text is None):
print("Empty text....")
continue
text = text.lower()
UH.SingleLinePrinter()
UH.PrintRightSide("User:"+text)
UH.SingleLinePrinter()
if(text in DS.start):
V_OP.speech("Service starting. Listening for voice commands")
FlagForServiceStart = True
continue
if(text in DS.stopCode):
confirmation = "Do you really want to stop this program?"
V_OP.speech(confirmation)
while(True):
text = VR.SpeechToText()
if(text is None):
print("Empty text...")
V_OP.speech("please confirm. "+ confirmation)
continue
UH.SingleLinePrinter()
UH.PrintRightSide("User:"+text)
UH.SingleLinePrinter()
text = text.lower()
if(text in DS.Yes):
V_OP.speech("Thank you for using our service. use again!")
UH.DesignPrinter()
t.sleep(1.5)
exit()
elif(text in DS.No):
V_OP.speech("Listening for voice commands")
FlagForServiceStart = True
break
else:
V_OP.speech("please confirm. "+ confirmation)
continue
if(not FlagForServiceStart):
print("Listenening but not recognising until services start again...")
if(FlagForServiceStart):
#for volume control
if(text in DS.IncreaseVolume ):
VC.VolumeIncrease()
# print("Increased the volume")
elif(text in DS.DecreaseVolume):
VC.VolumeDecrease()
elif(text in DS.VolumeMute):
VC.VolumeMute()
elif(text in DS.VolumeUnMute):
VC.UnMute(text)
elif(text in DS.FullVolume):
VC.VolumeFull()
elif(text in DS.HalfVolume):
VC.VolumeHalf()
#for brightness
elif(text in DS.IncreaseBrightness):
BC.BrightnessIncrease()
elif(text in DS.DecreaseBrightness):
BC.BrightnessDecrease()
elif(text in DS.FullBrightness):
BC.BrightnessFull()
elif(text in DS.FullLowBrightness):
BC.BrightnessFullLow()
elif(text in DS.BrightnessHalf):
BC.BrightnessHalf()
#for stopping services and code
elif(text in DS.Stop):
FlagForServiceStart = False
FlagForPrintServiceRunning = False
V_OP.speech("Service stopping, until you start again")
#for returning current voice and brightness level
elif(text in DS.C_Bri_Level):
BC.SayCurrentBrightnessLevel()
elif(text in DS.C_Vol_Level):
VC.SayCurrentVolume()
#receiving confirmation and then terminating the program
elif(text in DS.stopCode):
confirmation = "Do you really want to stop this program?"
V_OP.speech(confirmation)
while(True):
text = VR.SpeechToText()
if(text is None):
print("Empty text...")
V_OP.speech("please confirm. "+ confirmation)
continue
UH.SingleLinePrinter()
UH.PrintRightSide("User:"+text)
UH.SingleLinePrinter()
text = text.lower()
if(text in DS.Yes):
V_OP.speech("Thank you for using our service. use again!")
UH.DesignPrinter()
t.sleep(1.5)
exit()
elif(text in DS.No):
V_OP.speech("Listening for voice commands")
FlagForServiceStart = True
break
else:
V_OP.speech("please confirm. "+ confirmation)
continue
else:
# print("Check your voice command. Did you just said "+text+"?")
V_OP.speech("Check your voice command. Did you just said "+text+"?")
matches = DS.MatchCommand(text)
# print("Do you mean ")
n = len(matches)
if(len(matches) > 5):
n = 5
if(len(matches) != 0):
V_OP.speech("Do you mean ")
for i in range(0,n):
MediateText = (i == (n - 1)) and "." or ", or"
V_OP.speech(matches[i] + MediateText)
# print(matches[i] + MediateText)
# print("If you said anything by mistake or you are talking to someone else, you can simply pause this program by saying 'pause' or 'stop'")
V_OP.speech("If you said anything by mistake or you are talking to someone else, you can simply pause this program by saying 'pause' or 'stop'")