-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiniMate.py
93 lines (76 loc) · 2.65 KB
/
MiniMate.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
93
# this is the minimate code that runs on the computer!
# again, these codes are samples: a lot more can be done with them
# in another update i'll be commenting more lines to explain code
# TODO: use serial over bluetooth instead of usb so minimate can move around
from pvrecorder import PvRecorder
import pvrhino, pvcheetah
from joke.jokes import geek, icanhazdad, chucknorris, icndb
from random import choice
import pyttsx3
import serial
print('\n\n\n\n\n')
engine = pyttsx3.init()
ultimateJoke = lambda jokeType=choice([geek, icanhazdad, chucknorris, icndb]): jokeType()
# this is the port my arduino is connected to
arduino = serial.Serial('/dev/cu.wchusbserial220',115200)
# sorry, i'm not giving away my access key!
key='PICOVOICE_CODE'
cheetah = pvcheetah.create(access_key=key)
rhino = pvrhino.create(
access_key=key,
context_path='Mini-Mate-Commands_en_mac_v2_1_0.rhn'
)
# replace the sound device string with the name of your mix
# run print(PvRecorder.get_audio_devices()) to get a list of connected devices
recorder = PvRecorder(device_index=PvRecorder.get_audio_devices().index('USB PnP Sound Device'),frame_length=512)
recorder.start()
# I made a function for this so that the recorder wouldnt spam errors
def say(x):
recorder.stop()
engine.say(x)
engine.runAndWait()
recorder.start()
say("Minimate Ready!")
def getNextAudioFrame():
return recorder.read()
def jokeAround():
arduino.write(b'j')
print('jo')
say(ultimateJoke())
def dance():
arduino.write(b'd')
print('da')
say('One can not but dance in such a situation')
def spin():
arduino.write(b's')
print("sp")
say('Spinnnny')
# this function is being updated!
def search():
print('se')
say(f'So you wanna know about {cheetah.flush()}, huh?')
while True:
audioFrame = getNextAudioFrame()
isFinalized = rhino.process(audioFrame)
isEndpoint = cheetah.process(getNextAudioFrame())[1]
if isFinalized:
inference = rhino.get_inference()
if inference.is_understood:
recorder.stop()
intent = inference.intent
slots = inference.slots
recorder.start()
print(f"\n\nintent: {intent}\nslots: {slots}\n\n")
match intent:
case 'do':
if 'joke' in list(slots.values()):
jokeAround()
elif 'dance' in list(slots.values()):
dance()
elif 'spin' in list(slots.values()):
spin()
case 'search':
if isEndpoint:
print(cheetah.flush())
rhino.delete()
cheetah.delete()