You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.4 KiB
108 lines
3.4 KiB
#include "zlinuxcomponents/zmainhelper.hpp"
|
|
//
|
|
#include "configs/config.hpp"
|
|
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|
#include "iflytopcpp/core/thread/thread.hpp"
|
|
#include "spdlog/spdlog.h"
|
|
#include "version.hpp"
|
|
#include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
|
|
#include "zservice_container/zservice_container.hpp"
|
|
//
|
|
#include "service/device_io_service.hpp"
|
|
#include "service/device_io_service_mock.hpp"
|
|
#include "service/light_control_service.hpp"
|
|
#include "service/report_service.hpp"
|
|
#include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
|
|
|
|
//
|
|
#include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp"
|
|
// #include "zlinuxcomponents/audio/audio_recoder.hpp"
|
|
#include <curl/curl.h>
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include "zlinuxcomponents/aiui_ws/aiui.h"
|
|
|
|
//
|
|
using namespace iflytop;
|
|
using namespace core;
|
|
using namespace std;
|
|
using namespace clipp;
|
|
|
|
ZMAIN();
|
|
void Main::onSIGINT() { exit(0); }
|
|
int Main::main(int argc, char *argv[]) {
|
|
string g_host_server_ip;
|
|
string g_device_id;
|
|
spdlog::flush_on(spdlog::level::debug);
|
|
|
|
const char *appid = "5938b7c7"; // 应用ID,在AIUI开放平台创建并设置
|
|
const char *key = "19c1f7becc78eedc7826b485aabe30de"; // 接口密钥,在AIUI开放平台查看
|
|
const char *param =
|
|
"{\"result_level\":\"plain\",\"auth_id\":\"ac30105366ea460f9ff08ddac0c4f71e\",\"data_"
|
|
"type\":\"text\","
|
|
"\"scene\":\"main_box\",\"sample_rate\":\"16000\", "
|
|
"\"context\":\"{\\\"sdk_support\\\":[\\\"nlp\\\",\\\"tts\\\"]}\"}";
|
|
|
|
json paramj;
|
|
paramj["result_level"] = "plain";
|
|
paramj["auth_id"] = "ac30105366ea460f9ff08ddac0c4f71e";
|
|
paramj["data_type"] = "text";
|
|
paramj["scene"] = "main_box";
|
|
paramj["sample_rate"] = "16000";
|
|
paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})";
|
|
// logger->info("{}", paramj.dump());
|
|
// logger->info("{}", param);
|
|
|
|
shared_ptr<AiuiService> aiuiService(new AiuiService());
|
|
logger->info("test_asr_main.cpp");
|
|
aiuiService->initialize(appid, key, paramj.dump());
|
|
aiuiService->aiuiInit();
|
|
aiuiService->onMessage.connect([&](json &rxjson) {
|
|
//
|
|
string action = rxjson["action"];
|
|
if (action == "started") {
|
|
logger->info("rx started:{}", rxjson.dump());
|
|
}
|
|
//
|
|
else if (action == "result") {
|
|
string sub = rxjson["data"]["sub"];
|
|
if (sub == "nlp") {
|
|
logger->info("rx nlp:{}", rxjson.dump());
|
|
} else if (sub == "tts") {
|
|
logger->info("rx tts:frame {}", rxjson["data"]["json_args"]["frame_id"].get<int>());
|
|
bool isendFrame = false;
|
|
string ttsurl;
|
|
aiuiService->parseTTSContent(rxjson, isendFrame, ttsurl);
|
|
if (isendFrame) {
|
|
logger->info("rx tts end,url={}", ttsurl);
|
|
}
|
|
} else if (sub == "iat") {
|
|
logger->info("rx iat:{}", rxjson.dump());
|
|
} else if (sub == "vad") {
|
|
logger->info("rx vad:{}", rxjson.dump());
|
|
} else {
|
|
logger->info("rx {}:{}", sub, rxjson.dump());
|
|
}
|
|
}
|
|
//
|
|
else if (action == "error") {
|
|
logger->info("rx error:{}", rxjson.dump());
|
|
}
|
|
//
|
|
else if (action == "vad") {
|
|
} else {
|
|
logger->info("rx unkown:{}", rxjson.dump());
|
|
}
|
|
|
|
try {
|
|
if (rxjson["data"]["is_finish"].get<bool>()) {
|
|
logger->info("end tx");
|
|
}
|
|
} catch (...) {
|
|
}
|
|
});
|
|
aiuiService->aiuiWrite("今天天气怎么样", strlen("今天天气怎么样"));
|
|
while (true) sleep(1000);
|
|
}
|