1、新增Function Calling的讲故事功能,可以语音获取小故事
This commit is contained in:
parent
7663018d4c
commit
d494a1025f
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ components/
|
||||
managed_components/
|
||||
build/
|
||||
.vscode/
|
||||
.cache/
|
||||
.devcontainer/
|
||||
sdkconfig.old
|
||||
sdkconfig
|
||||
|
||||
@ -899,6 +899,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
|
||||
// else if (strcmp(name->valuestring, "get_weather_aihub") == 0) {
|
||||
// ESP_LOGI(TAG, "[WeatherAPI] ===== 收到get_weather_aihub工具调用 =====");
|
||||
@ -1094,6 +1112,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1215,6 +1245,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);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "工具调用: name=%s arguments=%s", name->valuestring, args_str);
|
||||
@ -1267,6 +1309,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 新增代码(小程序控制 暂停/继续播放 音频)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user