Skip to content

Commit 3b9d26c

Browse files
authored
Merge pull request #227801 from eric-urban/eur/speech-clu-quickstart
Intent recognition with CLU
2 parents 00192d2 + 9bf9b1c commit 3b9d26c

19 files changed

+505
-102
lines changed

articles/cognitive-services/.openpublishing.redirection.cognitive-services.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,6 +4290,11 @@
42904290
"redirect_url": "/azure/cognitive-services/speech-service/speech-translation",
42914291
"redirect_document_id": false
42924292
},
4293+
{
4294+
"source_path_from_root": "/articles/cognitive-services/Speech-Service/index-intent-recognition.yml",
4295+
"redirect_url": "/azure/cognitive-services/speech-service/intent-recognition",
4296+
"redirect_document_id": false
4297+
},
42934298
{
42944299
"source_path_from_root": "/articles/cognitive-services/Speech-Service/intent.md",
42954300
"redirect_url": "/azure/cognitive-services/speech-service/how-to-recognize-intents-from-speech-csharp",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "Intent recognition with CLU quickstart - Speech service"
3+
titleSuffix: Azure Cognitive Services
4+
description: In this quickstart, you recognize intents from audio data with the Speech service and Language service.
5+
services: cognitive-services
6+
author: eric-urban
7+
manager: nitinme
8+
ms.service: cognitive-services
9+
ms.subservice: speech-service
10+
ms.topic: quickstart
11+
ms.date: 02/22/2023
12+
ms.author: eur
13+
zone_pivot_groups: programming-languages-set-thirteen
14+
keywords: intent recognition
15+
---
16+
17+
# Quickstart: Recognize intents with Conversational Language Understanding
18+
19+
::: zone pivot="programming-language-csharp"
20+
[!INCLUDE [C# include](includes/quickstarts/intent-recognition-clu/csharp.md)]
21+
::: zone-end
22+
23+
::: zone pivot="programming-language-cpp"
24+
[!INCLUDE [C++ include](includes/quickstarts/intent-recognition-clu/cpp.md)]
25+
::: zone-end
26+
27+
::: zone pivot="programming-language-java"
28+
[!INCLUDE [Java include](includes/quickstarts/intent-recognition-clu/java.md)]
29+
::: zone-end
30+
31+
## Next steps
32+
33+
> [!div class="nextstepaction"]
34+
> [Learn more about speech recognition](how-to-recognize-speech.md)

articles/cognitive-services/Speech-Service/get-started-intent-recognition.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: speech-service
1010
ms.topic: quickstart
11-
ms.date: 01/08/2022
11+
ms.date: 02/22/2023
1212
ms.author: eur
1313
ms.devlang: cpp, csharp, java, javascript, python
1414
ms.custom: devx-track-js, devx-track-csharp, cog-serv-seo-aug-2020, mode-other
@@ -18,6 +18,11 @@ keywords: intent recognition
1818

1919
# Quickstart: Recognize intents with the Speech service and LUIS
2020

21+
> [!IMPORTANT]
22+
> LUIS will be retired on October 1st 2025 and starting April 1st 2023 you will not be able to create new LUIS resources. We recommend [migrating your LUIS applications](/azure/cognitive-services/language-service/conversational-language-understanding/how-to/migrate-from-luis) to [conversational language understanding](/azure/cognitive-services/language-service/conversational-language-understanding/overview) to benefit from continued product support and multilingual capabilities.
23+
>
24+
> Conversational Language Understanding (CLU) is available for C# and C++ with the [Speech SDK](speech-sdk.md) version 1.25 or later. See the [quickstart](get-started-intent-recognition-clu.md) to recognize intents with the Speech SDK and CLU.
25+
2126
::: zone pivot="programming-language-csharp"
2227
[!INCLUDE [C# include](includes/quickstarts/intent-recognition/csharp.md)]
2328
::: zone-end

articles/cognitive-services/Speech-Service/how-to-use-custom-entity-pattern-matching.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ ms.subservice: speech-service
1010
ms.topic: how-to
1111
ms.date: 11/15/2021
1212
ms.author: chschrae
13-
ms.devlang: cpp, csharp
1413
zone_pivot_groups: programming-languages-set-thirteen
1514
ms.custom: devx-track-cpp, devx-track-csharp, mode-other
1615
---
@@ -31,10 +30,9 @@ In this guide, you use the Speech SDK to develop a console application that deri
3130
3231
## When to use pattern matching
3332

34-
Use this sample code if:
35-
* You're only interested in matching strictly what the user said. These patterns match more aggressively than LUIS.
36-
* You don't have access to a [LUIS](../LUIS/index.yml) app, but still want intents.
37-
* You can't or don't want to create a [LUIS](../LUIS/index.yml) app but you still want some voice-commanding capability.
33+
Use pattern matching if:
34+
* You're only interested in matching strictly what the user said. These patterns match more aggressively than [conversational language understanding (CLU)](/azure/cognitive-services/language-service/conversational-language-understanding/overview).
35+
* You don't have access to a CLU model, but still want intents.
3836

3937
For more information, see the [pattern matching overview](./pattern-matching-overview.md).
4038

articles/cognitive-services/Speech-Service/how-to-use-simple-language-pattern-matching.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ In this guide, you use the Speech SDK to develop a C++ console application that
3030
3131
## When to use pattern matching
3232

33-
Use this sample code if:
34-
* You're only interested in matching strictly what the user said. These patterns match more aggressively than LUIS.
35-
* You don't have access to a [LUIS](../LUIS/index.yml) app, but still want intents.
36-
* You can't or don't want to create a [LUIS](../LUIS/index.yml) app but you still want some voice-commanding capability.
33+
Use pattern matching if:
34+
* You're only interested in matching strictly what the user said. These patterns match more aggressively than [conversational language understanding (CLU)](/azure/cognitive-services/language-service/conversational-language-understanding/overview).
35+
* You don't have access to a CLU model, but still want intents.
3736

3837
For more information, see the [pattern matching overview](./pattern-matching-overview.md).
3938

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
author: eric-urban
3+
ms.service: cognitive-services
4+
ms.subservice: speech-service
5+
ms.date: 02/17/2023
6+
ms.topic: include
7+
ms.author: eur
8+
---
9+
10+
> [!div class="checklist"]
11+
> * Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
12+
> * [Create a Language resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics)Create a Language resource</a> in the Azure portal.
13+
> * Get the Language resource key and endpoint. After your Language resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).
14+
> * [Create a Speech resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices) in the Azure portal.
15+
> * Get the Speech resource key and region. After your Speech resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).

articles/cognitive-services/Speech-Service/includes/common/azure-prerequisites-luis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ ms.author: eur
1010
> [!div class="checklist"]
1111
> * Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
1212
> * <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics" title="Create a Language resource" target="_blank">Create a Language resource</a> in the Azure portal. You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production. You won't need a Speech resource this time.
13-
> * Get the resource key and region. After your Language resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).
13+
> * Get the Language resource key and region. After your Language resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).

articles/cognitive-services/Speech-Service/includes/common/azure-prerequisites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ ms.author: eur
1010
> [!div class="checklist"]
1111
> * Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
1212
> * <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Create a Speech resource</a> in the Azure portal.
13-
> * Get the resource key and region. After your Speech resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).
13+
> * Get the Speech resource key and region. After your Speech resource is deployed, select **Go to resource** to view and manage keys. For more information about Cognitive Services resources, see [Get the keys for your resource](~/articles/cognitive-services/cognitive-services-apis-create-account.md#get-the-keys-for-your-resource).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: eric-urban
3+
ms.service: cognitive-services
4+
ms.subservice: speech-service
5+
ms.topic: include
6+
ms.date: 01/25/2022
7+
ms.author: eur
8+
---
9+
10+
You can use the [Azure portal](~/articles/cognitive-services/cognitive-services-apis-create-account.md#clean-up-resources) or [Azure Command Line Interface (CLI)](~/articles/cognitive-services/cognitive-services-apis-create-account-cli.md#clean-up-resources) to remove the Language and Speech resources you created.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
author: eric-urban
3+
ms.service: cognitive-services
4+
ms.subservice: speech-service
5+
ms.date: 02/17/2023
6+
ms.topic: include
7+
ms.author: eur
8+
---
9+
10+
[!INCLUDE [Header](../../common/cpp.md)]
11+
12+
[!INCLUDE [Introduction](intro.md)]
13+
14+
## Prerequisites
15+
16+
[!INCLUDE [Prerequisites](../../common/azure-prerequisites-clu.md)]
17+
18+
## Set up the environment
19+
The Speech SDK is available as a [NuGet package](https://www.nuget.org/packages/Microsoft.CognitiveServices.Speech) and implements .NET Standard 2.0. You install the Speech SDK later in this guide, but first check the [SDK installation guide](../../../quickstarts/setup-platform.md?pivots=programming-language-cpp) for any more requirements.
20+
21+
### Set environment variables
22+
23+
[!INCLUDE [Environment variables](../../common/environment-variables.md)]
24+
25+
## Create a Conversational Language Understanding project
26+
27+
[!INCLUDE [Deploy CLU model](deploy-clu-model.md)]
28+
29+
You'll use the project name and deployment name in the next section.
30+
31+
## Recognize intents from a microphone
32+
33+
Follow these steps to create a new console application and install the Speech SDK.
34+
35+
1. Create a new C++ console project in Visual Studio Community 2022 named `SpeechRecognition`.
36+
1. Install the Speech SDK in your new project with the NuGet package manager.
37+
```powershell
38+
Install-Package Microsoft.CognitiveServices.Speech
39+
```
40+
1. Replace the contents of `SpeechRecognition.cpp` with the following code:
41+
42+
```cpp
43+
#include <iostream>
44+
#include <stdlib.h>
45+
#include <speechapi_cxx.h>
46+
47+
using namespace Microsoft::CognitiveServices::Speech;
48+
using namespace Microsoft::CognitiveServices::Speech::Audio;
49+
using namespace Microsoft::CognitiveServices::Speech::Intent;
50+
51+
std::string GetEnvironmentVariable(const char* name);
52+
53+
int main()
54+
{
55+
// This example requires environment variables named:
56+
// "LANGUAGE_KEY", "LANGUAGE_ENDPOINT", "SPEECH_KEY", and "SPEECH_REGION"
57+
auto languageKey = GetEnvironmentVariable("LANGUAGE_KEY");
58+
auto languageEndpoint = GetEnvironmentVariable("LANGUAGE_ENDPOINT");
59+
auto speechKey = GetEnvironmentVariable("SPEECH_KEY");
60+
auto speechRegion = GetEnvironmentVariable("SPEECH_REGION");
61+
62+
auto cluProjectName = "YourProjectNameGoesHere";
63+
auto cluDeploymentName = "YourDeploymentNameGoesHere";
64+
65+
if ((size(languageKey) == 0) || (size(languageEndpoint) == 0) || (size(speechKey) == 0) || (size(speechRegion) == 0)) {
66+
std::cout << "Please set LANGUAGE_KEY, LANGUAGE_ENDPOINT, SPEECH_KEY, and SPEECH_REGION environment variables." << std::endl;
67+
return -1;
68+
}
69+
70+
auto speechConfig = SpeechConfig::FromSubscription(speechKey, speechRegion);
71+
72+
speechConfig->SetSpeechRecognitionLanguage("en-US");
73+
74+
auto audioConfig = AudioConfig::FromDefaultMicrophoneInput();
75+
auto intentRecognizer = IntentRecognizer::FromConfig(speechConfig, audioConfig);
76+
77+
std::vector<std::shared_ptr<LanguageUnderstandingModel>> models;
78+
79+
auto cluModel = ConversationalLanguageUnderstandingModel::FromResource(
80+
languageKey,
81+
languageEndpoint,
82+
cluProjectName,
83+
cluDeploymentName);
84+
85+
models.push_back(cluModel);
86+
intentRecognizer->ApplyLanguageModels(models);
87+
88+
std::cout << "Speak into your microphone.\n";
89+
auto result = intentRecognizer->RecognizeOnceAsync().get();
90+
91+
if (result->Reason == ResultReason::RecognizedIntent)
92+
{
93+
std::cout << "RECOGNIZED: Text=" << result->Text << std::endl;
94+
std::cout << " Intent Id: " << result->IntentId << std::endl;
95+
96+
// There is a known issue with the LanguageUnderstandingServiceResponse_JsonResult
97+
// property when used with CLU in the Speech SDK version 1.25.
98+
// The following should return JSON in a future release.
99+
std::cout << " Intent Service JSON: " << result->Properties.GetProperty(PropertyId::LanguageUnderstandingServiceResponse_JsonResult) << std::endl;
100+
}
101+
else if (result->Reason == ResultReason::RecognizedSpeech)
102+
{
103+
std::cout << "RECOGNIZED: Text=" << result->Text << " (intent could not be recognized)" << std::endl;
104+
}
105+
else if (result->Reason == ResultReason::NoMatch)
106+
{
107+
std::cout << "NOMATCH: Speech could not be recognized." << std::endl;
108+
}
109+
else if (result->Reason == ResultReason::Canceled)
110+
{
111+
auto cancellation = CancellationDetails::FromResult(result);
112+
std::cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
113+
114+
if (cancellation->Reason == CancellationReason::Error)
115+
{
116+
std::cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
117+
std::cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
118+
std::cout << "CANCELED: Did you update the subscription info?" << std::endl;
119+
}
120+
}
121+
}
122+
123+
std::string GetEnvironmentVariable(const char* name)
124+
{
125+
#if defined(_MSC_VER)
126+
size_t requiredSize = 0;
127+
(void)getenv_s(&requiredSize, nullptr, 0, name);
128+
if (requiredSize == 0)
129+
{
130+
return "";
131+
}
132+
auto buffer = std::make_unique<char[]>(requiredSize);
133+
(void)getenv_s(&requiredSize, buffer.get(), requiredSize, name);
134+
return buffer.get();
135+
#else
136+
auto value = getenv(name);
137+
return value ? value : "";
138+
#endif
139+
}
140+
```
141+
142+
1. In `SpeechRecognition.cpp` set the `cluProjectName` and `cluDeploymentName` variables to the names of your project and deployment. For information about how to create a CLU project and deployment, see [Create a Conversational Language Understanding project](#create-a-conversational-language-understanding-project).
143+
1. To change the speech recognition language, replace `en-US` with another [supported language](~/articles/cognitive-services/speech-service/supported-languages.md). For example, `es-ES` for Spanish (Spain). The default language is `en-US` if you don't specify a language. For details about how to identify one of multiple languages that might be spoken, see [language identification](~/articles/cognitive-services/speech-service/language-identification.md).
144+
145+
[Build and run](/cpp/build/vscpp-step-2-build) your new console application to start speech recognition from a microphone.
146+
147+
> [!IMPORTANT]
148+
> Make sure that you set the `LANGUAGE_KEY`, `LANGUAGE_ENDPOINT`, `SPEECH__KEY`, and `SPEECH__REGION` environment variables as described [above](#set-environment-variables). If you don't set these variables, the sample will fail with an error message.
149+
150+
Speak into your microphone when prompted. What you speak should be output as text:
151+
152+
```console
153+
Say something ...
154+
RECOGNIZED: Text=Go ahead and delete the e-mail.
155+
Intent Id: Delete.
156+
Language Understanding JSON:
157+
```
158+
159+
> [NOTE]
160+
> There is a known issue with the LanguageUnderstandingServiceResponse_JsonResult property when used with CLU in the Speech SDK version 1.25. You can get detailed JSON output in a future release. Via JSON, the intents are returned in the probability order of most likely to least likely. For example, the `topIntent` might be `Delete` with a confidence score of 0.95413816 (95.41%). The second most likely intent might be `Cancel` with a confidence score of 0.8985081 (89.85%).
161+
162+
## Remarks
163+
Now that you've completed the quickstart, here are some additional considerations:
164+
165+
- This example uses the `RecognizeOnceAsync` operation to transcribe utterances of up to 30 seconds, or until silence is detected. For information about continuous recognition for longer audio, including multi-lingual conversations, see [How to recognize speech](~/articles/cognitive-services/speech-service/how-to-recognize-speech.md).
166+
- To recognize speech from an audio file, use `FromWavFileInput` instead of `FromDefaultMicrophoneInput`:
167+
```cpp
168+
auto audioInput = AudioConfig::FromWavFileInput("YourAudioFile.wav");
169+
```
170+
- For compressed audio files such as MP4, install GStreamer and use `PullAudioInputStream` or `PushAudioInputStream`. For more information, see [How to use compressed input audio](~/articles/cognitive-services/speech-service/how-to-use-codec-compressed-audio-input-streams.md).
171+
172+
## Clean up resources
173+
174+
[!INCLUDE [Delete resource](../../common/delete-resource-clu.md)]
175+

0 commit comments

Comments
 (0)