1 #include <yarp/os/all.h> 5 if (!yarp::os::Network::isConnected(
ears_port.getName(),
"/ears/rpc")) {
6 if (yarp::os::Network::connect(
ears_port.getName(),
"/ears/rpc")) {
7 yInfo() <<
"Recog connected to ears";
10 yDebug() <<
"Recog didn't connect to ears";
14 if (yarp::os::Network::isConnected(
portRPC.getName(),
"/speechRecognizer/rpc")){
18 return yarp::os::Network::connect(
portRPC.getName(),
"/speechRecognizer/rpc");
36 if (!yarp::os::Network::isConnected(
ears_port.getName(),
"/ears/rpc")){
37 yarp::os::Network::connect(
ears_port.getName(),
"/ears/rpc");
39 if (yarp::os::Network::isConnected(
ears_port.getName(),
"/ears/rpc")) {
40 yarp::os::Bottle cmd, reply;
41 cmd.addString(
"listen");
48 yDebug() <<
"[listen] Listen sending command" << cmd.toString();
50 yDebug() <<
"[listen] Listen got reply" << reply.toString();
53 yWarning() <<
"[listen] No connection to ears available...";
58 if (!yarp::os::Network::isConnected(
ears_port.getName(),
"/ears/rpc")){
59 yarp::os::Network::connect(
ears_port.getName(),
"/ears/rpc");
61 if (yarp::os::Network::isConnected(
ears_port.getName(),
"/ears/rpc")) {
62 yarp::os::Bottle cmd, reply;
63 cmd.addString(
"listen");
64 cmd.addString(
"offShouldWait");
65 yDebug() <<
"[waitForEars] Listen sending command" << cmd.toString();
67 yDebug() <<
"[waitForEars] Listen got reply" << reply.toString();
70 yWarning() <<
"[waitForEars] No connection to ears available...";
75 yarp::os::Bottle bMessenger, bReply;
76 bMessenger.addString(
"interrupt");
78 portRPC.write(bMessenger, bReply);
79 if(bReply.get(1).asString() !=
"OK") {
80 yError() <<
"speechRecognizer was not interrupted";
81 yDebug() <<
"Reply from speechRecognizer:" << bReply.toString();
90 if (!yarp::os::Network::isConnected(
portRPC.getName(),
"/speechRecognizer/rpc")){
91 if (!yarp::os::Network::connect(
portRPC.getName(),
"/speechRecognizer/rpc")){
92 yarp::os::Bottle bReply;
94 bReply.addString(
"recog not connected");
95 yWarning(
" recog not connected");
102 yarp::os::Bottle bMessenger;
103 yarp::os::Bottle bReply;
104 bMessenger.addString(
"recog");
105 bMessenger.addString(
"grammarXML");
106 bMessenger.addString(sInput);
107 portRPC.write(bMessenger, bReply);
118 if (!yarp::os::Network::isConnected(
portRPC.getName(),
"/speechRecognizer/rpc")){
119 if (!yarp::os::Network::connect(
portRPC.getName(),
"/speechRecognizer/rpc")){
120 yarp::os::Bottle bReply;
122 bReply.addString(
"recog not connected");
123 yWarning(
" recog not connected");
127 std::ostringstream osError;
128 bool fGetaReply =
false;
129 yarp::os::Bottle bMessenger,
134 if (!keepEarsEnabled) {
141 bMessenger.addString(
"recog");
142 bMessenger.addString(
"grammarXML");
143 bMessenger.addString(sInput);
152 while (!fGetaReply && loop < iLoop)
155 portRPC.write(bMessenger, bReply);
157 yInfo() <<
" Reply from Speech Recog : " << bReply.toString();
159 if (bReply.toString() ==
"NACK" || bReply.size() < 2)
162 osError <<
"Check grammar";
163 bOutput.addString(osError.str());
164 yError() <<
" " << osError.str();
165 if (!keepEarsDisabledAfterRecog)
enableEars(
true);
168 else if (bReply.get(0).toString() ==
"0")
171 osError <<
"Grammar not recognized";
172 bOutput.addString(osError.str());
173 yError() <<
" " << osError.str();
174 if (!keepEarsDisabledAfterRecog)
enableEars(
true);
177 else if (bReply.get(0).toString() ==
"ACK")
179 if (bReply.get(1).toString() ==
"-1")
181 yError() <<
"Only found Garbage...";
182 yError() <<
"Check Why this happens";
186 yInfo() <<
"Sentence Acknowledged";
187 bAnswer = *bReply.get(1).asList();
189 if (bAnswer.toString() !=
"" && !bAnswer.isNull())
193 bOutput.addList() = bAnswer;
205 osError <<
"no vocal input";
206 bOutput.addString(osError.str());
207 yDebug() << osError.str();
209 if (!keepEarsDisabledAfterRecog)
enableEars(
true);
yarp::os::Bottle recogFromGrammarLoop(std::string sInput, int iLoop=50, bool keepEarsEnabled=false, bool keepEarsDisabledAfterRecog=false)
From one grxml grammar, return the first non-empty sentence recognized can last for several timeout (...
yarp::os::RpcClient portRPC
bool interruptSpeechRecognizer()
Interrupt the speech recognizer.
Abstract class to handle sub-systems of the icub-client.
yarp::os::RpcClient ears_port
Port to /ears/rpc.
SubSystem_Recog(const std::string &masterName)
Default constructor.
yarp::os::Bottle recogFromGrammar(std::string &sInput)
From one grxml grammar, return the sentence recognized for one timeout This is not supported...
virtual void Close()
Clean up resources.
void enableEars(bool on)
Send a command to ears whether it should listen to the speechRecognizer.
void waitForEars()
Send a command to ears that it should stop listening to the speechRecognizer, and wait until it hands...