1、本次新增了Function Calling的讲故事功能,可以语音获取小故事

This commit is contained in:
Rdzleo 2026-03-02 15:34:41 +08:00
parent 7082d2a818
commit 04d26d7cee

View File

@ -931,6 +931,24 @@ void Application::Start() {
} }
} }
} }
// 讲故事功能通过WebSocket发送故事请求
else if (strcmp(name->valuestring, "obtain_story") == 0) {
ESP_LOGI(TAG, "收到obtain_story工具调用通过WebSocket请求故事");
cJSON* sn = cJSON_GetObjectItem(args_obj, "story_name");
const char* story = (sn && cJSON_IsString(sn) && sn->valuestring) ? sn->valuestring : "random";
ESP_LOGI(TAG, "故事名称: %s", story);
// 打断当前播放 + 通过WebSocket发送故事请求和按story按钮一样
AbortSpeaking(kAbortReasonNone);
SendStoryRequest();
std::string msg = "正在为你获取故事";
cJSON* call_id_item = cJSON_GetObjectItem(call, "id");
const char* call_id = (call_id_item && cJSON_IsString(call_id_item) && call_id_item->valuestring) ? call_id_item->valuestring : "";
if (protocol_ && call_id && call_id[0] != '\0') {
protocol_->SendFunctionResult(call_id, msg);
}
}
// // 添加天气查询功能处理 get_weather_aihub // // 添加天气查询功能处理 get_weather_aihub
// else if (strcmp(name->valuestring, "get_weather_aihub") == 0) { // else if (strcmp(name->valuestring, "get_weather_aihub") == 0) {
// ESP_LOGI(TAG, "[WeatherAPI] ===== 收到get_weather_aihub工具调用 ====="); // ESP_LOGI(TAG, "[WeatherAPI] ===== 收到get_weather_aihub工具调用 =====");
@ -1126,6 +1144,18 @@ void Application::Start() {
} }
} }
} }
// 讲故事功能通过WebSocket发送故事请求
else if (strcmp(name->valuestring, "obtain_story") == 0) {
ESP_LOGI(TAG, "收到obtain_story工具调用通过WebSocket请求故事");
AbortSpeaking(kAbortReasonNone);
SendStoryRequest();
std::string msg = "正在为你获取故事";
cJSON* call_id_item = cJSON_GetObjectItem(call, "id");
const char* call_id = (call_id_item && cJSON_IsString(call_id_item) && call_id_item->valuestring) ? call_id_item->valuestring : "";
if (protocol_ && call_id && call_id[0] != '\0') {
protocol_->SendFunctionResult(call_id, msg);
}
}
} }
} }
} }
@ -1305,6 +1335,18 @@ void Application::Start() {
} }
} }
} }
// 讲故事功能通过WebSocket发送故事请求
else if (strcmp(name->valuestring, "obtain_story") == 0) {
ESP_LOGI(TAG, "收到obtain_story工具调用通过WebSocket请求故事");
AbortSpeaking(kAbortReasonNone);
SendStoryRequest();
std::string msg = "正在为你获取故事";
cJSON* call_id_item = cJSON_GetObjectItem(root, "call_id");
const char* call_id = (call_id_item && cJSON_IsString(call_id_item) && call_id_item->valuestring) ? call_id_item->valuestring : "";
if (protocol_ && call_id && call_id[0] != '\0') {
protocol_->SendFunctionResult(call_id, msg);
}
}
cJSON_Delete(args_obj); cJSON_Delete(args_obj);
} else { } else {
ESP_LOGI(TAG, "工具调用: name=%s arguments=%s", name->valuestring, args_str); ESP_LOGI(TAG, "工具调用: name=%s arguments=%s", name->valuestring, args_str);
@ -1357,6 +1399,18 @@ void Application::Start() {
} }
} }
} }
// 讲故事功能通过WebSocket发送故事请求
else if (strcmp(name->valuestring, "obtain_story") == 0) {
ESP_LOGI(TAG, "收到obtain_story工具调用通过WebSocket请求故事");
AbortSpeaking(kAbortReasonNone);
SendStoryRequest();
std::string msg = "正在为你获取故事";
cJSON* call_id_item = cJSON_GetObjectItem(root, "call_id");
const char* call_id = (call_id_item && cJSON_IsString(call_id_item) && call_id_item->valuestring) ? call_id_item->valuestring : "";
if (protocol_ && call_id && call_id[0] != '\0') {
protocol_->SendFunctionResult(call_id, msg);
}
}
} }
} }
// 新增代码(小程序控制 暂停/继续播放 音频) // 新增代码(小程序控制 暂停/继续播放 音频)