[Project Introduction] AI Intelligent Robot Assistant

Speaking of robotic assistants, who do you think of? My first reaction will blurt out: Baymax! !
When the blogger first watched the movie "Big Hero 6", he was captured by this intelligent and omnipotent "man" . Although Baymax is a chubby and inflatable charging robot, it is known as the "guardian warm man". The reason is that it not only acts as a "private health consultant", but can also chat with the owner, tell jokes to the owner, and even take care of the owner's emotions . Finally, after my continuous study and exploration, I also own a Baymax of my own! ! Although I have only achieved part of it now, everything is difficult at the beginning. I believe that with the current foundation, as long as I continue to study in the future, I will definitely be able to improve it into a perfect "male god".

Project Description

This is a voice management tool that uses the human-computer interaction function of the Tuling platform, combined with the speech recognition and speech synthesis technology of the Baidu AI platform, and is written in C++ under Linux that can intelligently AI dialogue and execute voice commands . You can directly chat with my smart robot butler by voice, or let it tell you a joke, or let it execute some basic Linux commands for you, or start some applications under Linux.
PS: Play movies, check the weather, check the route, check personal health, automatically reply to mobile phone messages and other functions are still under development, follow the bloggers, so stay tuned...

Project technical points

  1. C++ STL
  2. HTTP third-party library
  3. Turing Robot
  4. Baidu speech recognition and speech synthesis
  5. Linux system / network programming
  6. Installation and use of various third-party libraries and third-party tools

Project demo

Insert picture description here

Project development process

1. Create a project directory, create a project directory, and introduce Baidu speech recognition SDK
Insert picture description here
2. Learn to use jsoncpp

  • Mainly use [StreamWriterBuilder, StreamWriter, CharReaderBuilder, CharReader, write function, parse function, Json::Value]
  • The following is an example of constructing json string and parameter description:
std::string Message2Json(std::string &Wmsg) 
		{
			Json::Value root;  //相当于一个万能容器,可存放任意类型
			Json::StreamWriterBuilder wb;    //可以向输入流中写文本的对象
			std::ostringstream os;   //输入流的缓冲区
			
			root["reqType"]=0;  //输入类型为文本
			Json::Value item1;
			Json::Value item1_1;
			item1_1["text"]=Wmsg;
			item1["inputText"]=item1_1;
			root["perception"]=item1;  //输入的信息
			Json::Value item2;
			item2["apiKey"]=apiKey;
			item2["userId"]=userID;
			root["userInfo"]=item2;  //用户相关参数
			
			std::unique_ptr<Json::StreamWriter> sw(wb.newStreamWriter());  //指向对象的智能指针
			sw->write(root,&os);     //向输入流缓冲区中写入root类型的数据
			std::string ret=os.str();  //提取输入流缓冲区内数据
			return ret;   }

Insert picture description here

Through the study of the document, I found that the serialization and deserialization of json is the process of parsing and constructing json strings, and json also supports nesting, such as json contains "json", even json also contains "json array", etc.

3. Design related classes in Baymax

Insert picture description here
Insert picture description here
Insert picture description here
The running process of my housekeeper:Insert picture description here

4. Implementation of Turing Robot Core Code
To realize intelligent dialogue with Turing Robot, we must complete the following functions:

std::string Talk(std::string &msg)
		{
			std::string json=Message2Json(msg);        //将我们的文本构造成json串
			std::string response=RequestRobot(json);   //用http请求机器人得到回复
			std::string echo=Json2Message(response);    //解析得到的json串
			return echo;                                //返回机器人的文本回复
		}

5. Calling logic

#include "Baymax.hpp"
using namespace std;
int main() {
		Baymax *bm = new Baymax;
	    bm->Run();
		return 0;
}

6. Command.etc command configuration file
Insert picture description here
7. Makefile file
Insert picture description here
8. Project complete
file Refer to my GitHub for the complete project file: https://github.com/girl-6/Linux/tree/master/Baymax
About the test content of the project Refer to the blog: project testing

Guess you like

Origin blog.csdn.net/ly_6699/article/details/98474680