6 changed files with 138 additions and 3 deletions
-
1CMakeLists.txt
-
2cmakepc.cmake
-
2dep/zlinuxcomponents
-
43src/service/voiceprocess/asr_service.cpp
-
26src/service/voiceprocess/asr_service.hpp
-
67src/test_asr_main.cpp
@ -1 +1 @@ |
|||
Subproject commit cc20701d9b4e719524821a98fb7b0a8334fbe3f9 |
|||
Subproject commit 2344b60385743afbe743660579ee72e8e9760552 |
@ -0,0 +1,43 @@ |
|||
#include "asr_service.hpp"
|
|||
|
|||
#include "zlinuxcomponents/aiui_ws/aiui.h"
|
|||
using namespace iflytop; |
|||
using namespace core; |
|||
using namespace std; |
|||
|
|||
static AiuiService *thisClass = nullptr; |
|||
|
|||
void aiui_message_cb(const char *data, int len) { |
|||
if (thisClass) { |
|||
thisClass->call_aiui_message_cb(data, len); |
|||
} |
|||
} |
|||
void aiui_error_cb(int code, const char *str) { |
|||
if (thisClass) { |
|||
thisClass->call_aiui_error_cb(code, str); |
|||
} |
|||
} |
|||
AiuiService::AiuiService() { thisClass = this; } |
|||
int AiuiService::aiuiInit(const char *appid, const char *key, const char *param) { |
|||
thisClass = this; |
|||
return aiui_init(appid, key, param, aiui_message_cb, aiui_error_cb); |
|||
} |
|||
int AiuiService::aiuiWrite(const char *audio, int len) { return aiui_write(audio, len); } |
|||
int AiuiService::aiuiFinished() { return aiui_finished(); } |
|||
void AiuiService::aiuiDestroy() { |
|||
aiui_destroy(); |
|||
thisClass = nullptr; |
|||
} |
|||
|
|||
void AiuiService::call_aiui_message_cb(const char *data, int len) { |
|||
try { |
|||
json j = json::parse(data); |
|||
onAsrResult(j); |
|||
} catch (const std::exception &e) { |
|||
logger->error("AiuiService::call_aiui_message_cb error: {}", e.what()); |
|||
} |
|||
} |
|||
void AiuiService::call_aiui_error_cb(int code, const char *str) { |
|||
logger->error("AiuiService::call_aiui_error_cb error: {} => {}", code, str); |
|||
onError(code, str); |
|||
} |
@ -0,0 +1,67 @@ |
|||
#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 "zwebservice/zwebservice.hpp"
|
|||
//
|
|||
#include "service/device_io_service.hpp"
|
|||
#include "service/device_io_service_mock.hpp"
|
|||
#include "service/light_control_service.hpp"
|
|||
#include "service/main_control_service.hpp"
|
|||
#include "service/report_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(); |
|||
/***********************************************************************************************************************
|
|||
* =======================================================Main======================================================== * |
|||
***********************************************************************************************************************/ |
|||
static void onmessage(const char *data, int len) {} |
|||
static void onerror(int code, const char *str) { printf("aiui_init onerror %d => %s\n", code, str); } |
|||
|
|||
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\\\"]}\"}"; |
|||
|
|||
aiui_init(appid, key, param, onmessage, onerror); |
|||
|
|||
const char *text = "播放音乐"; |
|||
|
|||
aiui_write(text, strlen(text)); |
|||
|
|||
aiui_finished(); |
|||
|
|||
aiui_destroy(); |
|||
|
|||
while (true) sleep(1000); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue