音量調整
322字程度約1分
2024-11-07
开発者は、ユーザーが语したすべての言葉を取得し、それを使って意味図を推測し、決意を実行できます。ここでの決定には通常、家電の制御、デバイス自体の制御、通信可能なすべてのデバイスの制御が含まれます。
DilectiveSET のおかげで、ディレクティしてほとんどすべてのことを行うことができます。いくつかの一般的なシナリオを以下に示します。
Nodejs コード
const config = {
gen_client_config: async (){
return {
intention: [
{
key: async (text = "") => {
const pattern = /音量调到(\d+)\%/;
// 查找匹配项
const match = text.match(pattern);
if (match) {
return true;
}
},
// 配置开放平台 api_key 后字符串类型的指令会进行NLP推理。
api_key: "xxx",
instruct: ({ text }) => {
const pattern = /音量调到(\d+)\%/;
const match = text.match(pattern);
const volumeLevel = match[1];
console.log("音量设置为:", volumeLevel);
// 直接传给业务服务,业务服务可再传给硬件,这样硬件就可以进行调整音量了
// ...
},
message: "好的"
}
]
}
}
}Arduino コード
#include <esp-ai.h>
ESP_AI esp_ai;
WebSocketsClient webSocket_yw;
// 连接业务服务
void webScoket_yw_main() {
Serial.println("开始连接业务 ws 服务\n");
// ws 服务
webSocket_yw.begin( "ip", "端口", "路径");
webSocket_yw.onEvent(webSocketEvent_ye);
}
void webSocketEvent_ye(WStype_t type, uint8_t *payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.println("业务ws服务已断开\n");
break;
case WStype_CONNECTED:
{
Serial.println("√ 业务ws服务已连接\n");
break;
}
case WStype_TEXT:
{
JSONVar parseRes = JSON.parse((char *)payload);
if (JSON.typeof(parseRes) == "undefined") {
return;
}
if (parseRes.hasOwnProperty("type")) {
String type = (const char *)parseRes["type"];
if (type == "volume") {
int volume = (const int *)parseRes["volume"];
Serial.println(volume);
}
}
break;
}
case WStype_ERROR:
Serial.println("业务服务 WebSocket 连接错误");
break;
}
}
void setup() {
Serial.begin(115200);
esp_ai.begin({ ... });
}
void loop() {
esp_ai.loop();
webSocket_yw.loop();
}様に、上记のロジックを使用して任意のコマンドを実装できます。

