Skip to content

Commit 855b6e7

Browse files
committed
Changes to main
1 parent e14dcae commit 855b6e7

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

.DS_Store

0 Bytes
Binary file not shown.

iss.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
df['longitude'] = df.loc['longitude', 'iss_position']
99
df.reset_index(inplace=True)
1010

11-
df = df.drop(['index', 'message'], axis = 1)
11+
df = df.drop(['index', 'message'], axis=1)
1212

1313
fig = px.scatter_geo(df, lat='latitude', lon='longitude')
1414
fig.show()
15-

main.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from button import Button
44
from query import answerQuery as aq
55
import speech_recognition as sr
6+
import os
7+
import platform
68

79
pygame.init()
810

@@ -39,6 +41,8 @@ def main():
3941
btnSearch = Button(WIDTH//4*3, HEIGHT//4, btnSearch, 0.8)
4042
btnQuit = Button(WIDTH//4*3, HEIGHT//8*7, btnQuit, 0.8)
4143
btnSearchVoice = Button(WIDTH//4*3, HEIGHT//2, btnSearchVoice, 0.8)
44+
btnSolarSystem = Button(WIDTH//10, HEIGHT//4*3, btnSolarSystem, 0.8)
45+
btnTrackISS = Button(WIDTH//5*3, HEIGHT//4*3, btnTrackISS, 0.8)
4246

4347
# TEXT INPUT
4448
baseFont = pygame.font.Font(None, 40)
@@ -75,22 +79,21 @@ def main():
7579
if btnSearch.draw(SCREEN):
7680
spaceQuery(userText)
7781
if btnSearchVoice.draw(SCREEN):
78-
voiceText = "Ask your question."
79-
80-
# DISPLAY VOICE INPUT
81-
voiceColour = voiceActiveColour
82-
pygame.draw.rect(SCREEN, voiceColour, voiceInputrect)
83-
voiceTextSurface = baseFont.render(
84-
voiceText, True, (255, 255, 255))
85-
SCREEN.blit(voiceTextSurface,
86-
(voiceInputrect.x+5, voiceInputrect.y+5))
87-
pygame.display.flip()
82+
voiceActive = True
8883
searchVoice = True
84+
voiceText = "Listening..."
85+
if btnSolarSystem.draw(SCREEN):
86+
return
87+
if btnTrackISS.draw(SCREEN):
88+
if platform.system() == "Windows":
89+
os.system("python iss.py")
90+
else:
91+
os.system("python3 iss.py")
8992
if btnQuit.draw(SCREEN):
9093
pygame.quit()
9194
sys.exit()
9295

93-
# DISPLAY AND TYPE IN TEXT INPUT
96+
# DISPLAY TEXT INPUT
9497
if active:
9598
colour = activeColour
9699
else:
@@ -101,13 +104,17 @@ def main():
101104
SCREEN.blit(textSurface, (inputRect.x+5, inputRect.y+5))
102105

103106
# DISPLAY VOICE INPUT
104-
voiceColour = voicePassiveColour
107+
if voiceActive:
108+
voiceColour = voiceActiveColour
109+
else:
110+
voiceColour = voicePassiveColour
105111
pygame.draw.rect(SCREEN, voiceColour, voiceInputrect)
106112
voiceTextSurface = baseFont.render(
107113
voiceText, True, (255, 255, 255))
108114
SCREEN.blit(voiceTextSurface, (voiceInputrect.x+5, voiceInputrect.y+5))
109115
pygame.display.flip()
110116

117+
# TEXT
111118
# Quits program if application is closed
112119
for event in pygame.event.get():
113120
if event.type == pygame.QUIT:
@@ -138,23 +145,30 @@ def main():
138145
userText += event.unicode
139146
if event.key == pygame.K_RETURN:
140147
spaceQuery(userText)
148+
149+
# VOICE
150+
if event.type == pygame.MOUSEBUTTONDOWN:
151+
if btnSearchVoice.rect.collidepoint(event.pos):
152+
voiceActive = True
153+
else:
154+
voiceActive = False
155+
141156
if searchVoice:
142-
# variable for checking if the program did't cath the voice
157+
# variable for checking if the program didn't catch the voice
143158
correct = True
144159
r = sr.Recognizer()
145160
while correct:
146161
text = ''
147162
with sr.Microphone() as source:
148163
# listen for 1 second to calibrate the energy threshold for ambient noise levels
149164
r.adjust_for_ambient_noise(source)
165+
# read the audio data from the default microphone, will record for 10 seconds
166+
# audio_data = r.record(source, duration=10)
150167
audio_data = r.listen(source)
151-
correct = True
168+
# convert speech to text
152169
try:
153170
text = r.recognize_google(audio_data)
154-
voiceText = "Did you say: " + text
155-
156-
# DISPLAY VOICE INPUT
157-
voiceColour = voicePassiveColour
171+
voiceText = text
158172
pygame.draw.rect(
159173
SCREEN, voiceColour, voiceInputrect)
160174
voiceTextSurface = baseFont.render(
@@ -163,28 +177,13 @@ def main():
163177
voiceTextSurface, (voiceInputrect.x+5, voiceInputrect.y+5))
164178
pygame.display.flip()
165179

166-
while correct:
167-
if btnSearchVoice.rect.collidepoint(event.pos):
168-
spaceQuery(voiceText)
169-
elif background.rect.collidepoint(event.pos):
170-
correct = False
171-
raise Exception()
180+
spaceQuery(voiceText)
172181
except:
173-
voiceText = "Sorry, I didn't get that. Try again."
174-
# DISPLAY VOICE INPUT
175-
voiceColour = voicePassiveColour
176-
pygame.draw.rect(
177-
SCREEN, voiceColour, voiceInputrect)
178-
voiceTextSurface = baseFont.render(
179-
voiceText, True, (255, 255, 255))
180-
SCREEN.blit(
181-
voiceTextSurface, (voiceInputrect.x+5, voiceInputrect.y+5))
182-
pygame.display.flip()
182+
voiceText = "Sorry, I didn't get that"
183183
main()
184-
searchVoice = False
185184

186-
# except sr.RequestError as e:
187-
#print("Could not request results from Google Speech Recognition service; {0}".format(e))
185+
# except sr.RequestError as e:
186+
#print("Could not request results from Google Speech Recognition service; {0}".format(e))
188187

189188
pygame.display.update()
190189

0 commit comments

Comments
 (0)