Skip to content

Commit cab76e2

Browse files
authored
Merge pull request #42248 from wolfma61/wolfma61/intentsample
replace intent samples with a working sample
2 parents 1198208 + a2c9430 commit cab76e2

File tree

4 files changed

+65
-115
lines changed

4 files changed

+65
-115
lines changed

articles/cognitive-services/Speech-Service/intent.md

Lines changed: 46 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -19,114 +19,55 @@ ms.author: wolfma
1919
> For instructions to download this sample and others, see [Samples for Speech SDK](samples.md).
2020
2121
> [!NOTE]
22-
> For all samples below, we assume the following top-level declarations are in place:
23-
>
24-
> ```csharp
25-
> using System;
26-
> using System.Threading.Tasks;
27-
> using Microsoft.CognitiveServices.Speech;
28-
> using Microsoft.CognitiveServices.Speech.Intent;
29-
> ```
30-
>
31-
> ```cpp
32-
> #include <speechapi_cxx.h>
22+
> Please obtain a subscription key first. In contrast to other services supported by the Cognitive Service Speech SDK, the Intent Recognition services requires a specific subscribtion key. [Here](https://www.luis.ai) you can find additional information about the intent recognition technology, as well as information on how to acquire a subscription key. Replace your own subscription key, the region of the service, as well as the AppId of your intent model in the appropriate place in the samples.
23+
24+
> [!NOTE]
25+
> For all samples below the following top-level declarations should be in place:
3326
>
34-
> using namespace std;
35-
> using namespace Microsoft::CognitiveServices::Speech;
36-
> using namespace Microsoft::CognitiveServices::Speech::Intent;
37-
> ```
27+
> [!code-cpp[](~/samples-cognitive-services-speech-sdk/Windows/cxx_samples/intent_recognition_samples.cpp#toplevel)]
3828
>
3929
> - - -
4030
41-
Intent Recognition Using Microphone
42-
43-
```csharp
44-
// Create a speech factory associated with your speech subscription
45-
var speechSubscriptionKey = "YourSpeechSubscriptionKey";
46-
var factory = RecognizerFactory.Instance;
47-
factory.SubscriptionKey = speechSubscriptionKey;
48-
49-
// Create an intent recognizer using microphone as audio input.
50-
using (var recognizer = factory.CreateIntentRecognizer())
51-
{
52-
var intentName1 = "IntentNameFromLuisPortal";
53-
var intentName2 = "IntentNameFromLuisPortal";
54-
55-
var luisSubscriptionKey = "YourLuisSubscriptionKey";
56-
var luisEndpoint = "YourLuisEndpoint";
57-
var luisAppId = "YourLuisAppId";
58-
59-
// Create a LanguageUnderstandingModel to use with the intent recognizer
60-
var model = LanguageUnderstandingModel.From(luisEndpoint, luisSubscriptionKey, luisAppId);
61-
62-
// Add intents from your LU model to your intent recognizer
63-
recognizer.AddIntent("1", model, intentName1);
64-
recognizer.AddIntent("some other ID", model, intentName2);
65-
66-
// Prompt the user to speak
67-
Console.WriteLine("Say something...");
68-
69-
// Start recognition; will return the first result recognized
70-
var result = await recognizer.RecognizeAsync().ConfigureAwait(false);
71-
72-
// Check the reason returned
73-
if (result.Reason == RecognitionStatus.Success)
74-
{
75-
Console.WriteLine($"We recognized: {result.RecognizedText}");
76-
}
77-
else if (result.Reason == RecognitionStatus.NoMatch)
78-
{
79-
Console.WriteLine("We didn't hear you say anything...");
80-
}
81-
else if (result.Reason == RecognitionStatus.Canceled)
82-
{
83-
Console.WriteLine($"There was an error; reason {result.Reason}-{result.RecognizedText}");
84-
}
85-
}
86-
```
87-
88-
```cpp
89-
// Creates an instance of a speech factory with specified
90-
// subscription key. Replace with your own subscription key.
91-
auto factory = SpeechFactory::FromSubscription(L"YourSubscriptionKey", L"");
92-
93-
// Create an intent recognizer using microphone as audio input.
94-
auto recognizer = factory->CreateIntentRecognizer();
95-
96-
// Create a LanguageUnderstandingModel associated with your LU application
97-
auto luisSubscriptionKey = L"YourLuisSubscriptionKey";
98-
auto luisEndpoint = L"YourLuisEndpoint";
99-
auto luisAppId = L"YourLuisAppId";
100-
auto model = LanguageUnderstandingModel::From(luisEndpoint, luisSubscriptionKey, luisAppId);
101-
102-
// Add each intent you wish to recognize to the intent recognizer
103-
auto intentName1 = L"IntentNameFromLuisPortal";
104-
auto intentName2 = L"IntentNameFromLuisPortal";
105-
106-
recognizer->AddIntent(L"1", IntentTrigger::From(model, intentName1));
107-
recognizer->AddIntent(L"some other ID", IntentTrigger::From(model, intentName2));
108-
109-
// Prompt the user to speak
110-
wcout << L"Say something...\n";
111-
112-
// Start recognition; will return the first result recognized
113-
auto result = recognizer->RecognizeAsync().get();
114-
115-
// Check the reason returned
116-
if (result->Reason == Reason::Recognized)
117-
{
118-
wcout << L"We recognized: " << result->Text << '\n';
119-
wcout << L"IntentId=" << result->IntentId << '\n';
120-
wcout << L"json=" << result->Properties[ResultProperty::LanguageUnderstandingJson].GetString();
121-
}
122-
else if (result->Reason == Reason::NoMatch)
123-
{
124-
wcout << L"We didn't hear anything" << '\n';
125-
}
126-
else if (result->Reason == Reason::Canceled)
127-
{
128-
wcout << L"There was an error, reason " << int(result->Reason) << L"-" << result->ErrorDetails << '\n';
129-
}
130-
```
31+
## Intent Recognition Using Microphone
32+
33+
The code snippet below shows how to recognize intent from microphone input in the default language (`en-US`).
34+
35+
[!code-cpp[Intent Recognition Using Microphone](~/samples-cognitive-services-speech-sdk/Windows/cxx_samples/intent_recognition_samples.cpp#IntentRecognitionWithMicrophone)]
36+
37+
- - -
38+
39+
## Intent Recognition Using Microphone In a Specified Language
40+
41+
The code snippet below shows how to recognize intent from microphone input in a specified language, in this case in German (`de-de`).
42+
43+
[!code-cpp[Intent Recognition Using Microphone In A Specified Language](~/samples-cognitive-services-speech-sdk/Windows/cxx_samples/intent_recognition_samples.cpp#IntentRecognitionWithLanguage)]
13144

13245
- - -
46+
47+
## Intent Recognition From a File
48+
49+
The following code snippet recognizes intent from an audio file in the default language (`en-US`), the supported format is single-channel (mono) WAV / PCM with a sampling rate of 16 KHz.
50+
51+
[!include[Sample Audio](includes/sample-audio.md)]
52+
53+
[!code-cpp[Intent Recognition From a File](~/samples-cognitive-services-speech-sdk/Windows/cxx_samples/intent_recognition_samples.cpp?IntentRecognitionWithFile)]
54+
55+
- - -
56+
57+
## Intent Recognition Using Events
58+
59+
The code snippet shows how to recognize intent in a continuous way. This code allows access to additional information, like intermediate results.
60+
61+
[!code-cpp[Intent Recognition Using Events](~/samples-cognitive-services-speech-sdk/Windows/cxx_samples/intent_recognition_samples.cpp#IntentContinuousRecognitionUsingEvents)]
62+
63+
- - -
64+
65+
## Sample Source Code
66+
67+
The latest version of the samples and even more advanced samples are in a dedicated [GitHub repository](https://github.com/Azure-Samples/cognitive-services-speech-sdk).
68+
69+
## Next Steps
70+
71+
- [Speech Recognition](./speech-to-text-sample.md)
72+
73+
- [Translation](./translation.md)

articles/cognitive-services/Speech-Service/samples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ You can download compressed archives of the Windows and Linux samples and tutori
1818

1919
- [Download samples for Windows](https://aka.ms/csspeech/winsample)
2020
- [Download samples for Linux](https://aka.ms/csspeech/linuxsample)
21+
- [Sample Source Code GitHub Repository for Speech SDK](https://github.com/Azure-Samples/cognitive-services-speech-sdk)
22+
2123
- [Download sample for Android (only for the Speech Devices SDK)](https://github.com/Azure-Samples/Cognitive-Services-Speech-Devices-SDK)
2224

2325
All samples are provided under the MIT License.

articles/cognitive-services/Speech-Service/speech-to-text-sample.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ms.author: wolfma
2121
[!include[Get a Subscription Key](includes/get-subscription-key.md)]
2222

2323
> [!NOTE]
24-
> For all samples below, we assume the following top-level declarations are in place:
24+
> For all samples below, the following top-level declarations should be in place:
2525
>
2626
> [!code-csharp[](~/samples-cognitive-services-speech-sdk/Windows/csharp_samples/speech_recognition_samples.cs#toplevel)]
2727
>
@@ -41,9 +41,7 @@ The code snippet below shows how to recognize speech input from the microphone i
4141

4242
## Speech Recognition From a File
4343

44-
The code snippet below shows how to recognize speech input from a file in the default language (`en-US`),
45-
using the factory's `CreateSpeechRecognizerWithFileInput` member function.
46-
The audio format needs to be WAV / PCM with a single channel (mono) and 16 KHz sampling rate.
44+
The following code snippet recognizes speech input from an audio file in the default language (`en-US`), the supported format is single-channel (mono) WAV / PCM with a sampling rate of 16 KHz.
4745

4846
[!include[Sample Audio](includes/sample-audio.md)]
4947

@@ -55,9 +53,7 @@ The audio format needs to be WAV / PCM with a single channel (mono) and 16 KHz s
5553

5654
## Speech Recognition Using a Customized Model
5755

58-
The [Custom Speech Service (CRIS)](https://www.cris.ai/) allows to customize Microsoft's speech-to-text engine for your application.
59-
The snippet below shows how to recognize speech from a microphone using your CRIS model;
60-
fill in your CRIS subscription key and your own deployment ID before running it.
56+
The [Custom Speech Service (CRIS)](https://www.cris.ai/) allows the customization of the Microsoft's speech-to-text engine for your application. The snippet below shows how to recognize speech from a microphone using your CRIS model; fill in your CRIS subscription key and your own deployment identification before running it.
6157

6258
[!code-csharp[Speech Recognition Using a Customized Model](~/samples-cognitive-services-speech-sdk/Windows/csharp_samples/speech_recognition_samples.cs#recognitionCustomized)]
6359

@@ -73,9 +69,10 @@ fill in your CRIS subscription key and your own deployment ID before running it.
7369

7470
- - -
7571

76-
## Downloading the sample
72+
## Sample Source Code
73+
74+
The latest version of the samples and even more advanced samples are in a dedicated [GitHub repository](https://github.com/Azure-Samples/cognitive-services-speech-sdk).
7775

78-
The samples in this article are contained in the sample package; please download from [here](https://aka.ms/csspeech/winsample).
7976

8077
## Next steps
8178

articles/cognitive-services/Speech-Service/translation.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ms.author: wolfma
2121
[!include[Get a Subscription Key](includes/get-subscription-key.md)]
2222

2323
> [!NOTE]
24-
> For all samples below, we assume the following top-level declarations are in place:
24+
> For all samples below the following top-level declarations should be in place:
2525
>
2626
> [!code-csharp [Using Statements](~/samples-cognitive-services-speech-sdk/Windows/csharp_samples/translation_samples.cs#toplevel)]
2727
>
@@ -43,3 +43,13 @@ It uses file as input.
4343
[!code-csharp[Translation Using File Input](~/samples-cognitive-services-speech-sdk/Windows/csharp_samples/translation_samples.cs#TranslationWithFileAsync)]
4444

4545
- - -
46+
47+
## Sample Source Code
48+
49+
The latest version of the samples and even more advanced samples are in a dedicated [GitHub repository](https://github.com/Azure-Samples/cognitive-services-speech-sdk).
50+
51+
## Next Steps
52+
53+
- [Speech Recognition](./speech-to-text-sample.md)
54+
55+
- [Intent Recognition](./intent.md)

0 commit comments

Comments
 (0)