30 #include <SimoxUtility/json.h>
31 #include <SimoxUtility/algorithm/string.h>
33 #include <boost/regex.hpp>
39 using namespace ScanLocationGroup;
41 namespace fs = std::filesystem;
51 void NameRecognizedObjects::waitForSpeechFinished()
53 ARMARX_INFO <<
"Starting to wait for speech to finish";
55 while (!isRunningTaskStopped())
57 ARMARX_INFO <<
deactivateSpam(1) <<
"Speech observer status: " << getSpeechObserver()->getDatafieldByName(
"TextToSpeech",
"State")->getString();
58 if (getSpeechObserver()->getDatafieldByName(
"TextToSpeech",
"State")->getString() ==
"FinishedSpeaking")
60 ARMARX_IMPORTANT <<
"Speech observer status: " << getSpeechObserver()->getDatafieldByName(
"TextToSpeech",
"State")->getString();
65 if (isRunningTaskStopped())
76 static std::vector<std::string> getNamesFromChannels(std::vector<ChannelRefPtr>
const& channels,
77 std::map<std::string, std::string>
const& humanObjectNameMap)
79 boost::regex re(
"[^a-zA-Z0-9]+");
83 std::string
memoryName = channelRef->getDataField(
"className")->getString();
90 return boost::regex_replace(
memoryName, re, std::string(
" "));
94 std::vector<ChannelRefPtr>
const& objectInstanceChannels = channels;
95 std::vector<std::string> objectNames;
97 std::set<std::string> uniqueObjectNames;
100 auto resolvedName = resolveObjectName(p);
101 if (uniqueObjectNames.count(resolvedName))
105 uniqueObjectNames.insert(resolvedName);
106 objectNames.push_back(resolvedName);
114 std::map<std::string, std::string> humanObjectNameMap = in.getHumanObjectNameMap();
116 std::vector<std::string> recognizedObjectsVec = getNamesFromChannels(in.getObjectInstanceChannels(), humanObjectNameMap);
118 if (in.getUseObjectPoseStorage())
122 const std::vector<std::string> objPoseProviderNames = in.getObjectPoseProviderNames();
123 const std::set<std::string> objPoseProviderNamesSet(objPoseProviderNames.begin(), objPoseProviderNames.end());
125 ARMARX_INFO <<
"Got " << objectPoses.size() <<
" object poses.";
130 if (objPoseProviderNamesSet.count(objectPose.providerName))
132 const static bool includeClassName =
false;
133 const std::vector<std::string>
names = finder.
loadSpokenNames(objectPose.objectID, includeClassName);
136 const std::string objectName =
names.size() > 0 ?
names.front()
137 : objectPose.objectID.className();
138 recognizedObjectsVec.push_back(objectName);
142 std::set<std::string> recognizedObjects;
143 for (
const std::string& name : recognizedObjectsVec)
145 recognizedObjects.insert(simox::alg::to_lower(name));
148 std::vector<std::string>
display = in.getDisplay_Text();
154 std::vector<std::string> ttsSeq;
155 if (recognizedObjects.empty())
157 ttsSeq.push_back(
"I cannot see any objects that I know.");
158 display[1] =
"I did not find any objects.";
160 else if (recognizedObjects.size() == 1)
162 const std::string resolvedName = *recognizedObjects.begin();
163 ttsSeq.push_back(
"I can see " + resolvedName);
164 display[1] =
"I can see the " + resolvedName;
168 ttsSeq.push_back(
"I can see the following objects: ");
169 for (
const std::string& objectName : recognizedObjects)
171 ttsSeq.push_back(
" a " + objectName +
"");
179 if (in.getReportObjectsWithSpeech())
181 for (
auto tts : ttsSeq)
183 getTextToSpeech()->reportText(tts);
184 if (in.getWaitForSpeechToFinish())
186 waitForSpeechFinished();