20 if (recog_result ==
"none_result")
57 for (
int j = 0; j < 4; j++)
66 std::cout <<
"Can not find the answer corresponding to the keyword. Please check " 67 "the configuration file " 77 std::ifstream file(answer_config_file);
119 std::cout <<
"Action mode is: " << action_mode << std::endl;
143 std::cout <<
"Error occurred in action_mode: " << action_mode << std::endl;
151 ask_json_ =
"{\"reqType\": 0, \"perception\": {\"inputText\" : {\"text\": " 154 "\"selfInfo\": {\"location\": {\"city\": \"北京\", \"province\": " 155 "\"\",\"street\": \"\"}}}, \"userInfo\": " 158 "\"userId\": \"0\"}}";
163 long totalSize = size * nmemb;
164 std::string* symbolBuffer = (std::string*)content;
167 symbolBuffer->append((
char*)data, ((
char*)data) + totalSize);
178 curl_global_init(CURL_GLOBAL_ALL);
179 pCurl = curl_easy_init();
182 curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 2);
183 curl_easy_setopt(pCurl, CURLOPT_URL, tuling_url_.c_str());
184 curl_slist* plist = curl_slist_append(NULL,
"Content-Type:application/json;charset=UTF-8");
185 curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, plist);
186 std::cout <<
"Ask Json String is:" << ask_json_ << std::endl;
188 curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, ask_json_.c_str());
190 curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, http_data_writer);
191 curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, (
void*)&answer_json_);
192 res = curl_easy_perform(pCurl);
193 long responseCode = 0;
194 curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &responseCode);
197 std::cout <<
"curl_easy_perform() failed:" << curl_easy_strerror(res) << std::endl;
200 curl_easy_cleanup(pCurl);
202 curl_global_cleanup();
203 std::cout <<
"Tuling robot answer:" << answer_json_ << std::endl;
210 std::string result = answer_json_;
212 document.Parse(answer_json_.c_str());
214 if (document.HasParseError())
217 std::cout <<
"JSON解析错误" << code << std::endl;
221 if (document.HasMember(
"results"))
228 if (resultUnit.HasMember(
"values"))
233 answer_text_ = text.GetString();
234 std::cout << answer_text_ << std::endl;
std::istream & operator>>(std::istream &str, CSVOperation &data)
void setAskJson(const std::string ask_str)
设置图灵机器人对话请求参数.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
int actionDetect()
监测是否需要机器人控制以及控制类型..
std::vector< std::string > answerContent()
返回一个反馈内容(包含语音和动作的反馈).
static size_t http_data_writer(void *data, size_t size, size_t nmemb, void *content)
std::string callTulingApi()
请求图灵机器人接口,获取回答.
bool resultIsValid(const std::string recog_result)
判断语音识别结果是否为有效结果,若语音识别模块传来的结果!=none_result,则为有效.
std::vector< std::string > answer_dictionary_
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
ParseErrorCode
Error code of parsing.
void keywordResponse(const std::string log_path)
根据响应vector内的值调用不同的响应接口,如发布控制指令,播放音频文件等.
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
bool audioConverter(const std::string base_path, const char *src_text)
std::vector< std::vector< std::string > > readAllCSV(std::istream &str)
void uninitNLP()
一次处理结束后释放资源.
void readNextRow(std::istream &str)
std::string recog_final_result_
bool isKeywordRepeated(std::string key_word)
判断新加的关键词是否已被定义过.
common definitions and configuration
语音识别结果处理与机器人交互模块. TODO: 还需要添加版权、版本等信息
std::string textFromJson()
从图灵机器人的完整json回答中解析出最终需要的text回答.
void uninitTuling()
一次回答后释放资源.
bool keywordDetection()
根据交互模式answer_table_判断识别出的关键词是否有对应的响应策略. 若该关键词有对应的响应回复,存入响应向量answer_dictionary_(4).
std::vector< std::vector< std::string > > readAnswerTable(std::string answer_config_file)
读取离线对话库:defaultconfig/answer_dic.csv文件里的内容,存入answer_table_.
std::vector< std::vector< std::string > > answer_table_