“Wifi mode”的版本间的差异
502748957@qq.com(讨论 | 贡献) |
502748957@qq.com(讨论 | 贡献) |
||
第124行: | 第124行: | ||
|style="width: 25%;"|[[File:MicroAIYuyinShow2.JPG|300px|center|thumb|识别界面]] | |style="width: 25%;"|[[File:MicroAIYuyinShow2.JPG|300px|center|thumb|识别界面]] | ||
|} | |} | ||
+ | 观察串口返回识别结果: | ||
+ | [[File:MicroAIYuyinSerial.png|300px|center]] | ||
|} | |} | ||
<br> | <br> | ||
<br> | <br> | ||
<p style="font-size:115%">[[MicroAI Reference|返回MicroAI Reference界面]]</p> | <p style="font-size:115%">[[MicroAI Reference|返回MicroAI Reference界面]]</p> |
2018年12月12日 (三) 07:36的版本
WiFi音频播放/语音识别
所需硬件
电路搭建 将Battery、Core+、hub堆叠在一起,通过MicroUSB数据线接入电脑,使用传感器线连接MicroAI的UART(串口)。将耳机根据模块上的耳机标志插入,并下载如下程序至Core+。将两个碰撞传感器接在D4和D6口
代码 #include <Microduino_Key.h>
#include <Microduino_Ai.h>
#define WIFI_SSID "SSID" //路由器名称
#define WIFI_PWD "PW" //路由器密码
#define WEB_NUM 4
const char* webRadioUrl[WEB_NUM] = {
"https://http.qingting.fm/386.mp3",
"https://http.qingting.fm/387.mp3",
"https://http.qingting.fm/388.mp3",
"https://http.qingting.fm/389.mp3",
};
static uint8_t webRadioIndex = 0xFF;
DigitalKey touch1(D4);
DigitalKey touch2(D6);
MicroAi mAi(&Serial1);
char strBuf[64] = {0};
void setup() {
Serial.begin(115200);
touch1.begin(INPUT_PULLUP);
touch2.begin(INPUT_PULLUP);
Serial.print("MicroAi set mode: WIFI.");
Serial.println("start initiation. ");
if(mAi.begin(MODE_WIFI)){
Serial.println("init OK!");
}else{
Serial.println("init failed!");
while(1);
}
if(mAi.setWifi(WIFI_SSID, WIFI_PWD)){
Serial.println("set wifi ssid and password OK!");
}else{
Serial.println("set wifi ssid and password failed!");
while(1);
}
Serial.print("wifi connecting");
while(mAi.getRssi()==0){
Serial.print(".");
delay(1000);
}
Serial.println("\r\nwifi connected.");
delay(1000);
}
void loop() {
if(touch1.readEvent() == SHORT_PRESS) {
if(webRadioIndex < WEB_NUM-1)
webRadioIndex++;
else
webRadioIndex = 0;
mAi.playFile(webRadioUrl[webRadioIndex]);
}
if(touch2.readEvent() == SHORT_PRESS) {
delay(500);
Serial.print("AT start Rest: ");
if(mAi.startRest()){
Serial.println("OK!");
int32_t code = mAi.waitResult(strBuf);
if(code){
Serial.print("rest code: ");
Serial.print(code);
Serial.print(", result: ");
Serial.println(strBuf);
}else{
Serial.println("rest none ");
}
}else{
Serial.println("Failed!");
}
}
delay(50);
}
运行结果
播放时MicroAI点阵显示音乐播放特效
观察串口返回识别结果: |