Skip to content

Commit 07e745c

Browse files
authored
Merge pull request #113338 from xiaojul/jun_work
[Cog Svcs] update text and screenshots in custom command quickstarts
2 parents 22df463 + 9326191 commit 07e745c

8 files changed

+77
-43
lines changed

articles/cognitive-services/Speech-Service/how-to-custom-speech-commands-fulfill-sdk.md

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ title: How to fulfill commands from a client with the Speech SDK
33
titleSuffix: Azure Cognitive Services
44
description: In this article, we explain how to handle Custom Commands activities on a client with the Speech SDK.
55
services: cognitive-services
6-
author: don-d-kim
7-
manager: yetian
6+
author: trevorbye
7+
manager: nitinme
88

99
ms.service: cognitive-services
1010
ms.subservice: speech-service
1111
ms.topic: conceptual
12-
ms.date: 03/12/2020
13-
ms.author: donkim
12+
ms.date: 05/04/2020
13+
ms.author: trbye
1414
---
1515

1616
# Fulfill commands from a client with the Speech SDK (Preview)
@@ -23,22 +23,22 @@ In this article, you'll:
2323
- Receive and visualize the custom JSON payload contents from a C# UWP Speech SDK client application
2424

2525
## Prerequisites
26-
27-
- [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
28-
- An Azure subscription key for Speech service
29-
- [Get one for free](get-started.md) or create it on the [Azure portal](https://portal.azure.com)
30-
- A previously created Custom Commands app
31-
- [Quickstart: Create a Custom Command with Parameters (Preview)](./quickstart-custom-speech-commands-create-parameters.md)
32-
- A Speech SDK enabled client application
33-
- [Quickstart: Connect to a Custom Command application with the Speech SDK (Preview)](./quickstart-custom-speech-commands-speech-sdk.md)
26+
> [!div class = "checklist"]
27+
> * [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
28+
> * An Azure subscription key for Speech service:
29+
[Get one for free](get-started.md) or create it on the [Azure portal](https://portal.azure.com)
30+
> * A previously created Custom Commands app:
31+
[Quickstart: Create a Custom Command with Parameters (Preview)](./quickstart-custom-speech-commands-create-parameters.md)
32+
> * A Speech SDK enabled client application:
33+
[Quickstart: Connect to a Custom Command application with the Speech SDK (Preview)](./quickstart-custom-speech-commands-speech-sdk.md)
3434

3535
## Optional: Get started fast
3636

3737
This article describes, step by step, how to make a client application to talk to your Custom Commands application. If you prefer to dive right in, the complete, ready-to-compile source code used in this article is available in the [Speech SDK Samples](https://aka.ms/csspeech/samples).
3838

3939
## Fulfill with JSON payload
4040

41-
1. Open your previously created Custom Commands application from the [Speech Studio](https://speech.microsoft.com/)
41+
1. Open the Custom Commands application you previously created from [Quickstarts: Create a custom command with parameters](./quickstart-custom-speech-commands-create-parameters.md)
4242
1. Check the **Completion Rules** section to make sure you have the previously created rule that responds back to the user
4343
1. To send a payload directly to the client, create a new rule with a Send Activity action
4444

@@ -51,9 +51,7 @@ This article describes, step by step, how to make a client application to talk t
5151
| Conditions | Required Parameter - `OnOff` and `SubjectDevice` | Conditions that determine when the rule can run |
5252
| Actions | `SendActivity` (see below) | The action to take when the rule condition is true |
5353

54-
> [!div class="mx-imgBorder"]
55-
> ![Send Activity payload](media/custom-speech-commands/fulfill-sdk-send-activity-action.png)
56-
54+
1. Copy the JSON below to **Activity content**
5755
```json
5856
{
5957
"type": "event",
@@ -62,12 +60,14 @@ This article describes, step by step, how to make a client application to talk t
6260
"device": "{SubjectDevice}"
6361
}
6462
```
63+
> [!div class="mx-imgBorder"]
64+
> ![Send Activity payload](media/custom-speech-commands/fulfill-sdk-send-activity-action.png)
6565
6666
## Create visuals for device on or off state
6767

68-
In [Quickstart: Connect to a Custom Command application with the Speech SDK (Preview)](./quickstart-custom-speech-commands-speech-sdk.md) you created a Speech SDK client application that handled commands such as `turn on the tv`, `turn off the fan`. Now add some visuals so you can see the result of those commands.
68+
In [Quickstart: Connect to a Custom Command application with the Speech SDK](./quickstart-custom-speech-commands-speech-sdk.md), you created a Speech SDK client application that handled commands such as `turn on the tv`, `turn off the fan`. With some visuals added, you can see the result of those commands.
6969

70-
Add labeled boxes with text indicating **On** or **Off** using the following XML added to `MainPage.xaml.cs`
70+
Add labeled boxes with text indicating **On** or **Off** using the following XML added to `MainPage.xaml`
7171

7272
```xml
7373
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="20">
@@ -87,36 +87,57 @@ Add labeled boxes with text indicating **On** or **Off** using the following XML
8787
```
8888

8989
## Handle customizable payload
90+
### Add reference libraries
9091

91-
Now that you've created a JSON payload, you can add a reference to the [JSON.NET](https://www.newtonsoft.com/json) library to handle deserialization.
92+
Since you've created a JSON payload, you need to add a reference to the [JSON.NET](https://www.newtonsoft.com/json) library to handle deserialization.
93+
- Right-client your solution.
94+
- Choose **Manage NuGet Packages for Solution**, Select **Install**
95+
- Search for **Newtonsoft.json** in the update list, Update **Microsoft.NETCore.UniversalWindowsPlatform** to newest version
9296

9397
> [!div class="mx-imgBorder"]
9498
> ![Send Activity payload](media/custom-speech-commands/fulfill-sdk-json-nuget.png)
9599
96-
In `InitializeDialogServiceConnector` add the following to your `ActivityReceived` event handler. The additional code will extract the payload from the activity and change the visual state of the tv or fan accordingly.
100+
In `MainPage.xaml.cs', add
101+
- `using Newtonsoft.Json;`
102+
- `using Windows.ApplicationModel.Core;`
103+
104+
### Handle received payload
105+
106+
In `InitializeDialogServiceConnector`, replace the `ActivityReceived` event handler with following code. The modified `ActivityReceived` event handler will extract the payload from the activity and change the visual state of the tv or fan accordingly.
97107

98108
```C#
99109
connector.ActivityReceived += async (sender, activityReceivedEventArgs) =>
100110
{
101111
NotifyUser($"Activity received, hasAudio={activityReceivedEventArgs.HasAudio} activity={activityReceivedEventArgs.Activity}");
102112

103113
dynamic activity = JsonConvert.DeserializeObject(activityReceivedEventArgs.Activity);
114+
var name = activity?.name != null ? activity.name.ToString() : string.Empty;
104115

105-
if(activity?.name == "SetDeviceState")
116+
if (name.Equals("UpdateDeviceState"))
106117
{
107-
var state = activity?.state;
108-
var device = activity?.device;
109-
switch(device)
118+
Debug.WriteLine("Here");
119+
var state = activity?.device != null ? activity.state.ToString() : string.Empty;
120+
var device = activity?.device != null ? activity.device.ToString() : string.Empty;
121+
122+
if (state.Equals("on") || state.Equals("off"))
110123
{
111-
case "tv":
112-
State_TV.Text = state;
113-
break;
114-
case "fan":
115-
State_Fan.Text = state;
116-
break;
117-
default:
118-
NotifyUser($"Received request to set unsupported device {device} to {state}");
119-
break;
124+
switch (device)
125+
{
126+
case "tv":
127+
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
128+
CoreDispatcherPriority.Normal, () => { State_TV.Text = state; });
129+
break;
130+
case "fan":
131+
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
132+
CoreDispatcherPriority.Normal, () => { State_Fan.Text = state; });
133+
break;
134+
default:
135+
NotifyUser($"Received request to set unsupported device {device} to {state}");
136+
break;
137+
}
138+
}
139+
else {
140+
NotifyUser($"Received request to set unsupported state {state}");
120141
}
121142
}
122143

@@ -134,6 +155,8 @@ connector.ActivityReceived += async (sender, activityReceivedEventArgs) =>
134155
1. Select the Talk button
135156
1. Say `turn on the tv`
136157
1. The visual state of the tv should change to "On"
158+
> [!div class="mx-imgBorder"]
159+
> ![Send Activity payload](media/custom-speech-commands/fulfill-sdk-turn-on-tv.png)
137160
138161
## Next steps
139162

3.18 KB
Loading
19.1 KB
Loading
-7.67 KB
Loading
33.6 KB
Loading
-114 KB
Loading

articles/cognitive-services/Speech-Service/quickstart-custom-speech-commands-select-custom-voice.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ In this article, we'll select a custom output voice for the application we creat
3030
> ![Sample Sentences with parameters](media/custom-speech-commands/select-custom-voice.png)
3131
3232
> [!NOTE]
33-
> Custom voices can be created from the Custom Voice project page. Select the **Speech Studio** link, then **Custom Voice** to get started.
33+
> - For **Public voices**, **Neural types** are only available for specific regions. To check availability, see [standard and neural voices by region/endpoint](https://docs.microsoft.com/azure/cognitive-services/speech-service/regions#standard-and-neural-voices).
34+
> - For **Custom voices**, they can be created from the Custom Voice project page. See [Get Started with Custom Voice](./how-to-custom-voice.md).
3435
3536
Now the application will respond in the selected voice, instead of the default voice.
3637

articles/cognitive-services/Speech-Service/quickstart-custom-speech-commands-speech-sdk.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ After creating a hosted Custom Commands application, you can begin talking to it
1919
In this article, you'll:
2020

2121
- Publish a Custom Commands application and get an application identifier (App ID)
22-
- Create a client app using the Speech SDK to allow you to talk to your Custom Commands application
22+
- Create a Universal Windows Platform (UWP) client app using the Speech SDK to allow you to talk to your Custom Commands application
2323

2424
## Prerequisites
2525

2626
A Custom Commands application is required to complete this article. If you haven't created a Custom Commands application yet, you can do so in these previous quickstarts:
27-
28-
- [Quickstart: Create a Custom Command (Preview)](./quickstart-custom-speech-commands-create-new.md)
29-
- [Quickstart: Create a Custom Command with Parameters (Preview)](./quickstart-custom-speech-commands-create-parameters.md)
27+
> [!div class = "checklist"]
28+
> * [Quickstart: Create a Custom Command (Preview)](./quickstart-custom-speech-commands-create-new.md)
29+
> * [Quickstart: Create a Custom Command with Parameters (Preview)](./quickstart-custom-speech-commands-create-parameters.md)
3030
3131
You'll also need:
32-
33-
- [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
34-
- An Azure subscription key for Speech Services. [Get one for free](get-started.md) or create it on the [Azure portal](https://portal.azure.com)
32+
> [!div class = "checklist"]
33+
> * [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
34+
> * An Azure subscription key for Speech Services. [Get one for free](get-started.md) or create it on the [Azure portal](https://portal.azure.com)
35+
> * [Enable your device for development](https://docs.microsoft.com/windows/uwp/get-started/enable-your-device-for-development)
3536
3637
## Optional: Get started fast
3738

3839
This quickstart describes, step by step, how to make a client application to connect to your Custom Commands app. If you prefer to dive right in, the complete, ready-to-compile source code used in this quickstart is available in the [Speech SDK Samples](https://aka.ms/csspeech/samples) under the `quickstart` folder.
3940

4041
## Step 1: Publish Custom Commands application
4142

42-
1. Open your [previously created Custom Commands application](./quickstart-custom-speech-commands-create-new.md) and select **Publish**
43+
1. Open your [previously created Custom Commands application (Preview)](./quickstart-custom-speech-commands-create-new.md) and select **Publish**
4344

4445
> [!div class="mx-imgBorder"]
4546
> ![Publish application](media/custom-speech-commands/fulfill-sdk-publish-application.png)
4647
4748
1. Copy the App ID from the publish notification for later use
49+
1. Copy the Speech Resource Key for later use
4850

4951
## Step 2: Create a Visual Studio project
5052

@@ -124,7 +126,7 @@ Add the code-behind source as follows:
124126

125127
1. In **Solution Explorer**, open the code-behind source file `MainPage.xaml.cs` (grouped under `MainPage.xaml`)
126128

127-
1. Replace the file's contents with the following code:
129+
1. Replace the file's contents with the following code:
128130

129131
```csharp
130132
using Microsoft.CognitiveServices.Speech;
@@ -293,6 +295,11 @@ Add the code-behind source as follows:
293295
}
294296
}
295297
```
298+
> [!NOTE]
299+
> If you see error: "The type 'Object' is defined in an assembly that is not referenced"
300+
> 1. Right-client your solution.
301+
> 1. Choose **Manage NuGet Packages for Solution**, Select **Updates**
302+
> 1. If you see **Microsoft.NETCore.UniversalWindowsPlatform** in the update list, Update **Microsoft.NETCore.UniversalWindowsPlatform** to newest version
296303
297304
1. Add the following code to the method body of `InitializeDialogServiceConnector`
298305

@@ -414,3 +421,6 @@ Add the code-behind source as follows:
414421
> [!div class="nextstepaction"]
415422
> [How to: Fulfill commands on the client with the Speech SDK (preview)](./how-to-custom-speech-commands-fulfill-sdk.md)
416423
> [How To: Add validations to Custom Command parameters (Preview)](./how-to-custom-speech-commands-validations.md)
424+
425+
## Sample source code
426+
Check out our client sample codes at [GitHub-VoiceAssistant](https://github.com/Azure-Samples/Cognitive-Services-Voice-Assistant)

0 commit comments

Comments
 (0)