-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstartup.py
More file actions
60 lines (47 loc) · 1.27 KB
/
startup.py
File metadata and controls
60 lines (47 loc) · 1.27 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
# Setup LCD and print loading message for user
import Output
lcd = Output.CharLCD()
lcd.print("Loading...")
import time
import Input
import Prediction
# Setup Compenents
button = Input.Button()
mic = Input.Mic(lcd)
predict = Prediction.Predict(lcd)
"""
Event Loop
"""
done = False
count = 0
while not done:
# Prompt user to 'Press Button' to record
lcd.print("Press Button To\nStart Recording\n")
button.get_input()
time.sleep(0.15)
# Record Audio if stream object created successfully
if not mic.start_stream():
break
lcd.print("Press Button To\nStop Recording\n")
while not button.is_pressed():
mic.read_data()
mic.save_audio()
lcd.print("Predicting...\n")
# Classify instrument(s) and display results
instruments = predict.get_predictions(mic.filenames[mic.counter-1])
if len(instruments) > 0:
lcd.print("# of possible\ninstruments:" + str(len(instruments)))
time.sleep(3)
for i in range(0,len(instruments)):
lcd.print(instruments[i])
time.sleep(3)
# Allow for 10 audio sample classifications before demo terminates
if count == 10:
done = True
count += 1
"""
Teardown
"""
lcd.Cleanup()
button.cleanup()
mic.cleanup()