4448| 8
|
[2019参赛作品] 【脑洞大赛】语音识别模拟键盘设备 |
项目背景 之前和朋友做AI训练街霸游戏,想加入人工语音识别输出特定技能或者连环招式,以增加游戏的趣味性。也联想到目前某些游戏按键技能太多,经常操作跟不上思想。于是就想着开发一个 输出全靠吼的硬件。说盘就盘。 |
本帖最后由 Jeff2 于 2019-9-5 14:01 编辑 上面代码测试 开灯 口令能点亮LED说明LD3320通了 接下研究下KEYBORAD代码 arduino leonardo可以直接用arduino的keyboard实例 我这边经过修改后代码如下 [mw_shl_code=c,true]#include <Keyboard.h> #include <ld3320.h> #include <PinMap.h> VoiceRecognition Voice; //声明一个语音识别对象 bool lastCapsLockState; void setup() { // initialize control over the keyboard: Keyboard.begin(); TIMSK0 = 0; Voice.init(); //初始化VoiceRecognition模块 //add fun Voice.noiseTime(0x10); Voice.voiceMaxLength(0x14); Voice.micVol(0x55); Voice.addCommand("zhuo mian", 0); //添加指令,参数(指令内容,指令标签(可重复)) Voice.addCommand("hong", 0); Voice.addCommand("tui chu", 1); Voice.addCommand("xia ye", 2); Voice.addCommand("shang qu", 3); Voice.addCommand("di bu", 4); Voice.addCommand("zui shang", 5); Voice.addCommand("liu lang qi", 6); Voice.addCommand("guan bi", 7); Voice.addCommand("xian shi", 8); Voice.addCommand("qie huan", 9); Voice.addCommand("shui jiao", 10); Voice.addCommand("fang da", 11); Voice.addCommand("bi ge", 11); Voice.addCommand("suo xiao", 12); Voice.addCommand("si mou", 12); Voice.addCommand("mi ma", 13); Voice.addCommand("en", 14); Voice.addCommand("oh", 14); Voice.addCommand("pi", 14); Voice.addCommand("kiu", 14); Voice.addCommand("wu", 14); Voice.addCommand("a", 14); Voice.addCommand("ei", 14); Voice.addCommand("si", 14); Voice.addCommand("jie suo", 15); Voice.start();//开始识别 } void loop() { switch (Voice.read()) //判断识别 { case 0: //若是指令“ei” Keyboard.press(KEY_LEFT_GUI);//左win Keyboard.press('d'); break; case 1: //若是指令“B” Keyboard.press(KEY_ESC); //Keyboard.print("You pressed the button "); // Keyboard.print(counter); // Keyboard.println(" times."); break; case 2: Keyboard.press(KEY_PAGE_DOWN); break; case 3: Keyboard.press(KEY_PAGE_UP); break; case 4: Keyboard.press(KEY_END); break; case 5: Keyboard.press(KEY_HOME); break; case 6: Keyboard.press(KEY_LEFT_GUI);//左alt Keyboard.press('2'); break; case 7: Keyboard.press(KEY_LEFT_ALT); Keyboard.press(KEY_F4); break; case 8: Keyboard.press('f'); break; case 9: Keyboard.press(KEY_LEFT_ALT);//左alt Keyboard.press(KEY_TAB); break; case 10: Keyboard.press(KEY_LEFT_GUI);//左win delay(500); Keyboard.press('l'); Keyboard.release(KEY_LEFT_GUI); Keyboard.release('l'); break; case 11: Keyboard.press(KEY_RIGHT_CTRL); Keyboard.print('+'); break; case 12: Keyboard.press(KEY_RIGHT_CTRL); Keyboard.print('-'); break; case 13: Keyboard.println("1111"); break; case 14: ; break; case 15: Keyboard.press(KEY_RETURN); break; default: break; delayMicroseconds(20000); } Keyboard.releaseAll(); Keyboard.end();//结束键盘通讯 }[/mw_shl_code] |
来更新下 ----------------------------------------------0630 boom表 LD3320 arduino leonardo 杜邦线 面包板 软件要求: 先下载ld3320 库文件,并复制到arduino的libraries文件夹下。地址 http://www.waveshare.net/study/portal.php?mod=attachment&id=37 连接 LD3320 语音模块到arduino leonardo 3.3V -- VCC GND -- GND MISO -- D12 MOSI -- D11 SCK -- D13 NSS -- D4 RST -- D9 IRQ -- D2 WR -- GND 先做个简单测试 [mw_shl_code=c,true]#include <ld3320.h> VoiceRecognition Voice; //声明一个语音识别对象 #define Led 8 //定义LED控制引脚 void setup() { pinMode(Led,OUTPUT); //初始化LED引脚为输出模式 digitalWrite(Led,LOW); //LED引脚低电平 Voice.init(); //初始化VoiceRecognition模块 Voice.addCommand("kai deng",0); //添加指令,参数(指令内容,指令标签(可重复)) Voice.addCommand("guan deng",1); //添加指令,参数(指令内容,指令标签(可重复)) Voice.start();//开始识别 } void loop() { switch(Voice.read()) //判断识别 { case 0: //若是指令“kai deng” digitalWrite(Led,HIGH); //点亮LED break; case 1: //若是指令“guan deng” digitalWrite(Led,LOW);//熄灭LED break; default: break; } }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed