-
Notifications
You must be signed in to change notification settings - Fork 3
/
voice_controlled_drone.py
94 lines (69 loc) · 2.23 KB
/
voice_controlled_drone.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
from vosk import Model, KaldiRecognizer
import pyaudio
from djitellopy import Tello
import cv2
import time
img = cv2.imread(r'images/black_bg.jpg')
try:
drone = Tello()
drone.connect()
print(f"BATTERY : {drone.get_battery()}%")
except:
pass
classFile = 'gesture.names'
with open(classFile, 'rt') as f:
classNames = f.read().split('\n')
print()
print()
print()
print(classNames)
print()
print()
model= Model(r"vosk-model-small-en-in-0.4/vosk-model-small-en-in-0.4")
recognizer = KaldiRecognizer(model, 16000)
mic = pyaudio.PyAudio()
stream = mic.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
def main():
speed = 40
lr = fb = ud = 0
while True:
data = stream.read(4096)
cv2.putText(img, f"Battery : {drone.get_battery()}%", (170,30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 1, cv2.LINE_AA)
cv2.imshow('Image', img)
# cv2.waitKey(1)
img[:] = (0, 0, 0)
if recognizer.AcceptWaveform(data):
text = recognizer.Result()
print(text[14:-3])
command = text[14:-3]
command = command.lower()
cv2.putText(img, command, (64,100), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 255, 0), 2, cv2.LINE_AA)
cv2.imshow('Image', img)
cv2.waitKey(1)
if command == "exit":
break
if "land" in command:
drone.land()
break
elif "take off" in command:
drone.takeoff()
elif "forward" in command:
fb = speed
elif "backward" in command:
fb = -speed
elif "left" in command:
lr = -speed
elif "right" in command:
lr = speed
elif "up" in command:
ud = speed
elif "down" in command:
ud = -speed
elif "flip" in command:
drone.flip_left()
# send_rc_control(left_right_velocity, forward_backward_velocity, up_down_velocity, yaw_velocity)
drone.send_rc_control(lr, fb, ud, 0)
lr = fb = ud = 0
main()
cv2.destroyAllWindows()