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

Usability improvements #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
.vscode/

# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down
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: 19 additions & 7 deletions ros_msft_luis/launch/luis.launch
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<launch>
<arg name="azure_cs_luis_key" default="$(optenv azure_cs_luis_key)"/>
<arg name="azure_cs_luis_endpoint" default="$(optenv azure_cs_luis_endpoint)"/>
<arg name="azure_cs_luis_appid" default="$(optenv azure_cs_luis_appid)"/>
<arg name="azure_cs_luis_region" default="$(optenv azure_cs_luis_region)"/>

<arg name="azure_cs_kw_key" default="$(optenv azure_cs_kw_key)"/>
<arg name="azure_cs_kw" default="$(optenv azure_cs_kw)"/>
<arg name="azure_cs_kw_path" default="$(optenv azure_cs_kw_path)"/>
<arg name="azure_cs_kw_region" default="$(optenv 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 azure_cs_luis_key)" />
<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>
119 changes: 29 additions & 90 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,60 @@ 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 +407,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 +428,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 +440,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