from future import *
from futureKOI import KOI
items = []
i = 0
items.append('rock')
items.append('paper')
items.append('scissors')
i = 0
koi = KOI(tx='P2',rx='P12',id=1)
koi.init_cls() # init classifier
koi.screen_mode(2, cmd='K6')
screen.sync = 0
while True:
screen.fill((0, 0, 0))
if sensor.btnValue("a") and sensor.btnValue("b"):
koi.cls_save_model(model="model.json",cmd='K43') # saves the classifier model
buzzer.melody(1)
else:
if sensor.btnValue("a"):
sleep(0.2)
if not sensor.btnValue("b"):
koi.cls_add_tag(id=(items[int((i % 3 + 1) - 1)]),cmd='K41') # classifier add tag
buzzer.melody(4)
else:
if sensor.btnValue("b"):
sleep(0.2)
buzzer.tone(440,0.2)
if not sensor.btnValue("a"):
i += 1
screen.text("Now training:",0,10,1,(255, 255, 255))
screen.text((items[int((i % 3 + 1) - 1)]),0,30,2,(255, 255, 255))
screen.text("Press A to add tag",0,60,1,(255, 255, 255))
screen.text("Press B for next tag",0,80,1,(255, 255, 255))
screen.text("Press A+B to save",0,100,1,(255, 255, 255))
screen.refresh()
KOI Image Classification Sample Program
from future import *
from futureKOI import KOI
koi = KOI(tx='P2',rx='P12',id=1)
koi.screen_mode(2, cmd='K6')
koi.init_cls()
koi.cls_load_model(model="model.json",cmd='K44') # loads the classifier model
while True:
if sensor.btnValue("a"):
screen.clear()
screen.text((koi.cls_run(cmd='K42')),5,10,2,(255, 255, 255)) # displays the classified tag
screen.refresh()
Searches the face in a group and returns the person name.
face_token: The token to be searched.
groupName: The group name.
BaiduAi Text to Speech
koi.baiduAI_tts(text ,cmd="K78")
Generates a speech using BaiduAI.
-text: The text to be spoken.
Wifi and Baidu TTS Sample Program
from future import *
from futureKOI import KOI
koi = KOI(tx='P2',rx='P12',id=1)
koi.screen_mode(2, cmd='K6')
koi.connect_wifi(router="apname" ,pwd="password" ,cmd='K50')
while True:
if sensor.btnValue("a"):
koi.baiduAI_tts(txt='"hello"' ,cmd='K78')
sleep(0.2)
if sensor.btnValue("b"):
screen.clear()
screen.text((koi.get_ip(cmd='K54')),5,10,1,(255, 255, 255))
screen.refresh()
sleep(0.2)
Audio
Record Wav File
koi.audio_record(name)
Record and saves the wav file to the SD card.
name: The file name in wav format.
Play Wav File
koi.audio_play(name)
Plays a wav file from the SD card.
name: The file name in wav format.
Calibrate Ambient Noise
koi.audio_noisetap()
Calibrates the ambient noise for speech recognition.
Speech Recognition Add Tag
koi.speech_add_tag(tag)
Adds a speech tag.
tag: The tag name.
Get Speech Recognition Tag
koi.speech_run(cmd="K65")
Runs the speech recognition and returns the tag.
Save Speech Model
koi.speech_save_model(file)
Saves the speech model to the SD card.
file: The filename.
Load Speech Model
koi.speech_load_model(file)
Loads a speech model.
file: The filename.
Speech Recognition Training Sample Program
from future import *
from futureKOI import KOI
items = []
i = 0
items.append('rock')
items.append('paper')
items.append('scissors')
i = 0
koi = KOI(tx='P2',rx='P12',id=1)
koi.audio_noisetap()
koi.screen_mode(2, cmd='K6')
screen.sync = 0
while True:
screen.fill((0, 0, 0))
if sensor.btnValue("a") and sensor.btnValue("b"):
buzzer.melody(1)
koi.speech_save_model("speech.json")
else:
if sensor.btnValue("a"):
sleep(0.2)
if not sensor.btnValue("b"):
koi.speech_add_tag((items[int((i % 3 + 1) - 1)]))
else:
if sensor.btnValue("b"):
sleep(0.2)
buzzer.tone(440,0.2)
if not sensor.btnValue("a"):
i += 1
screen.text("Now training:",0,10,1,(255, 255, 255))
screen.text((items[int((i % 3 + 1) - 1)]),0,30,2,(255, 255, 255))
screen.text("Press A to add tag",0,60,1,(255, 255, 255))
screen.text("Press B for next tag",0,80,1,(255, 255, 255))
screen.text("Press A+B to save",0,100,1,(255, 255, 255))
screen.refresh()
Speech Recognition Sample Program
from future import *
from futureKOI import KOI
koi = KOI(tx='P2',rx='P12',id=1)
koi.audio_noisetap()
koi.speech_load_model("speech.json")
while True:
if sensor.btnValue("a"):
screen.clear()
screen.text((koi.speech_run(cmd='K65')),5,10,2,(255, 255, 255))
screen.refresh()
Miscellaneous
Reset KOI
koi.reset(cmd='k99')
Resets the KOI.
Stop Classifier and Face Yolo
koi.stop_kpu(cmd='k98')
Stops the KPU from running Classifier and Face Yolo.