Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Usability Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ooeygui committed Sep 24, 2021
1 parent b7e2db3 commit 5378b31
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 113 deletions.
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"C:\\opt\\ros\\melodic\\x64\\tools\\vcpkg\\installed\\x64-windows\\include\\**",
"C:\\opt\\ros\\melodic\\x64\\include\\**",
"C:\\ws\\luis_ws\\devel\\include\\**",
"C:\\opt\\ros\\melodic\\x64\\tools\\vcpkg\\installed\\x64-windows\\include\\**"
],
"name": "ROS"
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.autoComplete.extraPaths": [
"C:/ws/luis_ws/devel\\lib/site-packages",
"C:/opt/ros/melodic/x64\\lib/site-packages"
]
}
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,22 @@ To get started, navigate to the [LUIS console](https://www.luis.ai/), to create

Once you have completed the model, you can train and publish to a production slot. This will require you to associate the model with a prediction resource on Azure. Once that has been completed, you can configure the ROS node. The ROS node requires the following information from the [LUIS console](https://www.luis.ai/)

APP ID - In Manage Tab --> Settings --> App ID

Primary Key - In the Manage Tab --> Azure Resources --> Prediction Resources --> Primary Key

Location - In the Manage Tab --> Azure Resources --> Rediction Resources --> Location

The ROS node requires the following information from the portal of [speech studio](https://speech.microsoft.com/portal?noredirect=true)


Speech Resource Key

Region information example "westus" if it is "West US", "westus2" if it is "West US 2"
In addition to the Lanugage Understanding service, you will also need to construct a keyword model on [Microsoft Speech Studio](https://speech.microsoft.com/portal?noredirect=true). Select *Custom Keyword* in the UI to create a Custom Keyword Project, and follow the instructions to create the model.

| ROS Variable | Where to get it | UI Path
|--|--|--|
|`azure_cs_luis_appid` | [LUIS](https://www.luis.ai/) | Manage Tab -> Settings -> App ID |
|`azure_cs_luis_key` | [LUIS](https://www.luis.ai/) | Manage Tab -> Azure Resources -> Prediction Resources -> Primary Key |
|`azure_cs_luis_region` | [LUIS](https://www.luis.ai/) | Manage Tab -> Azure Resources -> Prediction Resources -> Location |
|`azure_cs_kw_key` | [Speech Studio](https://speech.microsoft.com/portal?noredirect=true) | Gear Icon -> Resource -> Subscription Key |
|`azure_cs_kw_path`| [Speech Studio](https://speech.microsoft.com/portal?noredirect=true) | Select the keyword resource -> Tune and Download Model |
|`azure_cs_kw` | You create it | *Robot* |

> Please note that the region needs to be lower case without spaces - for example, if the UI says "West US 2", please put "westus2"
The LUIS ROS node can be configured two ways - by embedded in the Azure resource keys in the launch file, or setting them in the environment.

> if you are committing launch files to an open source repo, it is best to use the environment method as to not leak your keys.

Windows:
``` batch
set azure_cs_luis_appid=<Enter your APP ID mentioned above>
Expand Down
26 changes: 16 additions & 10 deletions ros_msft_luis/launch/luis.launch
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<launch>
<arg name="azure_cs_luis_endpoint" default="$(env azure_cs_luis_key)"/>
<arg name="azure_cs_luis_key" default="$(env azure_cs_luis_key)"/>
<arg name="azure_cs_luis_endpoint" default="$(env azure_cs_luis_endpoint)"/>
<arg name="azure_cs_luis_endpoint" default="$(env azure_cs_luis_appid)"/>
<arg name="azure_cs_luis_endpoint" default="$(env azure_cs_luis_region)"/>
<arg name="azure_cs_luis_appid" default="$(env azure_cs_luis_appid)"/>
<arg name="azure_cs_luis_region" default="$(env azure_cs_luis_region)"/>

<arg name="azure_cs_kw_key" default="$(env azure_cs_kw_key)"/>
<arg name="azure_cs_kw" default="$(env azure_cs_kw)"/>
<arg name="azure_cs_kw_path" default="$(env azure_cs_kw_path)"/>
<arg name="azure_cs_kw_region" default="$(env azure_cs_kw_region)"/>

<node name="luis_test" pkg="ros_msft_luis" type="ros_msft_luis_node" output="screen">
<param name="luiskey" value="Enter your Primary Key mentioned in the luis portal" />
<param name="region" value="Enter your location mentioned in the luis portal" />
<param name="appid" value="Enter your APP ID mentioned in the luis portal" />
<param name="kwkey" value="Enter your key mentioned in the speech studio" />
<param name="kwregion" value="Enter your location mentioned in the speech studio" />
<param name="keywordpath" value="Enter the location of the of .table file that you downloaded from the speech studio" />
<param name="keyword" value="Enter your custom keyword" />
<param name="luiskey" value="$(arg robotId)" />
<param name="region" value="$(arg azure_cs_luis_region)" />
<param name="appid" value="$(arg azure_cs_luis_appid)" />
<param name="endpoint" value="$(arg azure_cs_luis_endpoint)" />

<param name="kwkey" value="$(arg azure_cs_kw_key)" />
<param name="kwregion" value="$(arg azure_cs_kw_region)" />
<param name="keywordpath" value="$(arg azure_cs_kw_path)" />
<param name="keyword" value="$(arg azure_cs_kw)" />
</node>
</launch>
118 changes: 29 additions & 89 deletions ros_msft_luis/src/azure_cs_luis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
#include <ros/ros.h>
#ifdef WIN32
#include <windows.h>
#endif

#include <iostream>
#include <speechapi_cxx.h>
#include <parson.h>
#include <curl/curl.h>
#include <resource_retriever/retriever.h>

#include <audio_common_msgs/AudioData.h>

#include <ros_msft_luis_msgs/Entity.h>
#include <ros_msft_luis_msgs/Intent.h>
#include <ros_msft_luis_msgs/TopIntent.h>


#ifdef WIN32
#include <windows.h>
#endif

#include <iostream>
#include <speechapi_cxx.h>
#include <parson.h>

using namespace std;
using namespace Microsoft::CognitiveServices::Speech;
using namespace Microsoft::CognitiveServices::Speech::Audio;
Expand Down Expand Up @@ -314,127 +315,61 @@ int main(int argc, char **argv)
ros::NodeHandle nhPrivate("~");
std::promise<void> recognitionEnd;

const char *env = std::getenv("azure_cs_luis_key");
if (env != nullptr)
{
g_luisKey = env;
}

env = std::getenv("azure_cs_luis_endpoint");
if (env != nullptr)
{
g_luisEndpoint = env;
}

env = std::getenv("azure_cs_speech_endpoint");
if (env != nullptr)
{
g_speechEndpoint = env;
}

env = std::getenv("azure_cs_luis_appid");
if (env != nullptr)
{
g_luisAppId = env;
}

env = std::getenv("azure_cs_luis_region");
if (env != nullptr)
{
g_luisRegion = env;
}

env = std::getenv("azure_cs_kw_key");
if (env != nullptr)
{
g_kwKey = env;
}

env = std::getenv("azure_cs_kw_region");
if (env != nullptr)
{
g_kwRegion = env;
}

env = std::getenv("azure_cs_kw_path");
if (env != nullptr)
{
g_keyWordPath = env;
}

env = std::getenv("azure_cs_kw");
if (env != nullptr)
{
g_keyWord = env;
}
// Parameters.
if (g_luisKey.empty() &&
!nhPrivate.getParam("luiskey", g_luisKey))
if (!nhPrivate.getParam("luiskey", g_luisKey))
{
ROS_ERROR("luis key has not been set");
nh.shutdown();
return 0;
}

if (g_luisRegion.empty() &&
!nhPrivate.getParam("region", g_luisRegion))
if (!nhPrivate.getParam("region", g_luisRegion))
{
ROS_ERROR("luis region has not been set");
nh.shutdown();
return 0;
}

if (g_luisAppId.empty() &&
!nhPrivate.getParam("appid", g_luisAppId))
if (!nhPrivate.getParam("appid", g_luisAppId))
{
ROS_ERROR("luis AppId has not been set");
nh.shutdown();
return 0;
}

if (g_kwKey.empty() &&
!nhPrivate.getParam("kwkey", g_kwKey))
if (!nhPrivate.getParam("kwkey", g_kwKey))
{
ROS_ERROR("luis KeyWord key has not been set");
nh.shutdown();
return 0;
}

if (g_kwRegion.empty() &&
!nhPrivate.getParam("kwregion", g_kwRegion))
if (!nhPrivate.getParam("kwregion", g_kwRegion))
{
ROS_ERROR("luis KeyWord region has not been set");
nh.shutdown();
return 0;
}

if (g_keyWord.empty() &&
!nhPrivate.getParam("keyword", g_keyWord))
if (!nhPrivate.getParam("keyword", g_keyWord))
{
ROS_ERROR("luis KeyWord value has not been set");
nh.shutdown();
return 0;
}

if (g_keyWordPath.empty() &&
!nhPrivate.getParam("keywordpath", g_keyWordPath))
if (!nhPrivate.getParam("keywordpath", g_keyWordPath))
{
ROS_ERROR("luis KeyWordPath has not been set");
nh.shutdown();
return 0;
}

if (g_luisEndpoint.empty())
{
nhPrivate.getParam("luisendpoint", g_luisEndpoint);
nhPrivate.getParam("luisendpoint", g_luisEndpoint);
nhPrivate.getParam("speechendpoint", g_speechEndpoint);
}

if (g_speechEndpoint.empty())
if ((g_luisEndpoint.empty() && !g_speechEndpoint.empty()) || (!g_luisEndpoint.empty() && g_speechEndpoint.empty()))
{
nhPrivate.getParam("speechendpoint", g_speechEndpoint);
}

if ((g_luisEndpoint.empty() && !g_speechEndpoint.empty()) || (!g_luisEndpoint.empty() && g_speechEndpoint.empty())) {
ROS_ERROR("To use containers, both luisendpoint and speechendpoint must be set");
nh.shutdown();
return 0;
Expand Down Expand Up @@ -473,14 +408,16 @@ int main(int argc, char **argv)
while (ros::ok())
{
// Subscribes to events.
recognizer->Recognizing.Connect([](const SpeechRecognitionEventArgs &e) {
recognizer->Recognizing.Connect([](const SpeechRecognitionEventArgs &e)
{
if (e.Result->Reason == ResultReason::RecognizingKeyword)
{
ROS_INFO("RECOGNIZING KEYWORD: Text= %s", e.Result->Text.c_str());
}
});

recognizer->Recognized.Connect([](const SpeechRecognitionEventArgs &e) {
recognizer->Recognized.Connect([](const SpeechRecognitionEventArgs &e)
{
if (e.Result->Reason == ResultReason::RecognizedKeyword)
{
ROS_INFO("RECOGNIZED KEYWORD: Text= %s", e.Result->Text.c_str());
Expand All @@ -492,7 +429,8 @@ int main(int argc, char **argv)
}
});

recognizer->Canceled.Connect([&recognitionEnd](const SpeechRecognitionCanceledEventArgs &e) {
recognizer->Canceled.Connect([&recognitionEnd](const SpeechRecognitionCanceledEventArgs &e)
{
ROS_DEBUG("CANCELED: Reason=%d", (int)e.Reason);

if (e.Reason == CancellationReason::Error)
Expand All @@ -503,11 +441,13 @@ int main(int argc, char **argv)
}
});

recognizer->SessionStarted.Connect([&recognitionEnd](const SessionEventArgs &e) {
recognizer->SessionStarted.Connect([&recognitionEnd](const SessionEventArgs &e)
{
ROS_DEBUG("SESSIONSTARTED: SessionId= %s", e.SessionId.c_str());
});

recognizer->SessionStopped.Connect([&recognitionEnd](const SessionEventArgs &e) {
recognizer->SessionStopped.Connect([&recognitionEnd](const SessionEventArgs &e)
{
ROS_DEBUG("SESSIONSTOPPED: SessionId= %s", e.SessionId.c_str());

recognitionEnd.set_value(); // Notify to stop recognition.
Expand Down

0 comments on commit 5378b31

Please sign in to comment.