-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (23 loc) · 809 Bytes
/
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
import numpy as np
from tensorflow.keras import models
from recording_helper import record_audio, terminate
from tf_helper import preprocess_audiobuffer
commands = ['down', 'go', 'left', 'no', 'right', 'stop', 'up', 'yes']
# Load the model in the new .keras format
loaded_model = models.load_model('saved_model.keras')
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