ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
使用AIUI语义前需要首先确保对应的appid已经开通语义功能,开通地址:(http://aiui.xfyun.cn/apps/index)。 ~~~ #pragma mark - aiui 发送数据 //aiui发送数据 void AiuiSendBuffer(const void *buffer ,int size , bool isEnd) { //是否最后一次数据 if(isEnd){ //发送结束标记 IAIUIMessage * stopWrite = IAIUIMessage::create(AIUIConstant::CMD_STOP_WRITE, 0, 0, "data_type=audio,sample_rate=16000"); m_angent->sendMessage(stopWrite); stopWrite->destroy(); } else { //发送音频数据 Buffer* pcmBuffer = Buffer::alloc(size); memcpy(pcmBuffer->data(), buffer, size); //msc.lng和msc.lat的值为经纬度信息,发送数据时需要传入,请参照demo的获取示例 IAIUIMessage * writeMsg = IAIUIMessage::create(AIUIConstant::CMD_WRITE,0, 0, "data_type=audio,sample_rate=16000,msc.lng=117.13825,msc.lat=31.83365 ", pcmBuffer); m_angent->sendMessage(writeMsg); writeMsg->destroy(); } } ~~~ #### **语义结果解析** ~~~ void TestListener::onEvent(IAIUIEvent& event) { switch (event.getEventType()) { //解析结果 case AIUIConstant::EVENT_RESULT: { using namespace VA; Json::Value bizParamJson; Json::Reader reader; if(!reader.parse(event.getInfo(), bizParamJson,false)){ NSLog(@"parse error!,getinfo=%s",event.getInfo()); } Json::Value data = (bizParamJson["data"])[0]; Json::Value params = data["params"]; Json::Value content = (data["content"])[0]; std::string sub = params["sub"].asString(); if(sub == "nlp"){ Json::Value empty; Json::Value contentId = content.get("cnt_id", empty); if(contentId.empty()){ NSLog(@"Content Id is empty"); break; } std::string cnt_id = contentId.asString(); Buffer *buffer = event.getData()->getBinary(cnt_id.c_str()); if(NULL != buffer){ const char * resultStr = (char *) buffer->data(); if(resultStr == NULL){ return; } NSLog(@"resultStr=%s",resultStr); } } } break; //错误处理 case AIUIConstant::EVENT_ERROR: { } break; } } ~~~