-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (23 loc) · 798 Bytes
/
Copy pathmain.py
File metadata and controls
29 lines (23 loc) · 798 Bytes
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
import numpy as np
from tensorflow.keras import models
from recording_helper import record_audio, terminate
from tf_helper import preprocess_audiobuffer
# !! Modify this in the correct order
commands = ['left', 'down', 'stop', 'up', 'right', 'no', 'go', 'yes']
loaded_model = models.load_model("saved_model")
def predict_mic():
audio = record_audio()
spec = preprocess_audiobuffer(audio)
prediction = loaded_model(spec)
label_pred = np.argmax(prediction, axis=1)
command = commands[label_pred[0]]
print("Predicted label:", command)
return command
if __name__ == "__main__":
from turtle_helper import move_turtle
while True:
command = predict_mic()
move_turtle(command)
if command == "stop":
terminate()
break