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.
 
 

43 lines
1.3 KiB

#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);
}