diff --git a/clients/csharp-wpf/VoiceAssistantClient/MainWindow.xaml.cs b/clients/csharp-wpf/VoiceAssistantClient/MainWindow.xaml.cs index fd5a93c9..d5c42bdf 100644 --- a/clients/csharp-wpf/VoiceAssistantClient/MainWindow.xaml.cs +++ b/clients/csharp-wpf/VoiceAssistantClient/MainWindow.xaml.cs @@ -139,7 +139,7 @@ protected override void OnContentRendered(EventArgs e) // URL, a URL override. If the client doesn't meet these requirements (e.g. on first // run), pop up the settings dialog to prompt for it. var hasSubscriptionKey = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKey); - var hasSubscriptionRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion); + var hasSubscriptionRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionRegion); var hasUrlOverride = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.UrlOverride); if (!hasSubscriptionKey || (!hasSubscriptionRegion && !hasUrlOverride)) @@ -204,89 +204,113 @@ private void InitSpeechConnector() { DialogServiceConfig config = null; - var hasSubscription = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKey); - var hasRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion); - var hasBotId = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.BotId); - var hasUrlOverride = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.UrlOverride); + var profile = this.settings.RuntimeSettings.Profile; + var hasSubscription = !string.IsNullOrWhiteSpace(profile.SubscriptionKey); + var hasAuthToken = !string.IsNullOrWhiteSpace(profile.AuthorizationToken); + var hasRegion = !string.IsNullOrWhiteSpace(profile.SubscriptionRegion); + var hasBotId = !string.IsNullOrWhiteSpace(profile.BotId); + var hasUrlOverride = !string.IsNullOrWhiteSpace(profile.UrlOverride); - if (hasSubscription && (hasRegion || hasUrlOverride)) + if ((hasSubscription || hasAuthToken) && (hasRegion || hasUrlOverride)) { - if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.CustomCommandsAppId)) + if (!string.IsNullOrWhiteSpace(profile.CustomCommandsAppId)) { // NOTE: Custom commands is a preview Azure Service. // Set the custom commands configuration object based on three items: // - The Custom commands application ID - // - Cognitive services speech subscription key. + // - Cognitive services speech subscription key or auth token. // - The Azure region of the subscription key(e.g. "westus"). - config = CustomCommandsConfig.FromSubscription(this.settings.RuntimeSettings.Profile.CustomCommandsAppId, this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion); - } - else if (hasBotId) - { - config = BotFrameworkConfig.FromSubscription(this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion, this.settings.RuntimeSettings.Profile.BotId); + config = + hasSubscription ? CustomCommandsConfig.FromSubscription( + profile.CustomCommandsAppId, + profile.SubscriptionKey, + profile.SubscriptionRegion) + : hasAuthToken ? CustomCommandsConfig.FromAuthorizationToken( + profile.CustomCommandsAppId, + profile.AuthorizationToken, + profile.SubscriptionRegion) + : throw new ArgumentException(); } else { // Set the bot framework configuration object based on two items: - // - Cognitive services speech subscription key. It is needed for billing and is tied to the bot registration. - // - The Azure region of the subscription key(e.g. "westus"). - config = BotFrameworkConfig.FromSubscription(this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion); + // - Cognitive services speech subscription key or auth token. This is needed for billing and is + // tied to the bot registration. + // - The Azure region of the subscription key (e.g. "westus"). + + config = + (hasSubscription && hasBotId) ? BotFrameworkConfig.FromSubscription( + profile.SubscriptionKey, + profile.SubscriptionRegion, + profile.BotId) + : (hasSubscription && !hasBotId) ? BotFrameworkConfig.FromSubscription( + profile.SubscriptionKey, + profile.SubscriptionRegion) + : (hasAuthToken && hasBotId) ? BotFrameworkConfig.FromAuthorizationToken( + profile.AuthorizationToken, + profile.SubscriptionRegion, + profile.BotId) + : (hasAuthToken && !hasBotId) ? BotFrameworkConfig.FromAuthorizationToken( + profile.AuthorizationToken, + profile.SubscriptionRegion) + : throw new ArgumentException(); } } - if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ConnectionLanguage)) + if (!string.IsNullOrWhiteSpace(profile.ConnectionLanguage)) { // Set the speech recognition language. If not set, the default is "en-us". - config.Language = this.settings.RuntimeSettings.Profile.ConnectionLanguage; + config.Language = profile.ConnectionLanguage; } - if (this.settings.RuntimeSettings.Profile.CustomSpeechEnabled) + if (profile.CustomSpeechEnabled) { // Set your custom speech end-point id here, as given to you by the speech portal https://speech.microsoft.com/portal. // Otherwise the standard speech end-point will be used. - config.SetServiceProperty("cid", this.settings.RuntimeSettings.Profile.CustomSpeechEndpointId, ServicePropertyChannel.UriQueryParameter); + config.SetServiceProperty("cid", profile.CustomSpeechEndpointId, ServicePropertyChannel.UriQueryParameter); // Custom Speech does not support cloud Keyword Verification at the moment. If this is not done, there will be an error // from the service and connection will close. Remove line below when supported. config.SetProperty("KeywordConfig_EnableKeywordVerification", "false"); } - if (this.settings.RuntimeSettings.Profile.VoiceDeploymentEnabled) + if (profile.VoiceDeploymentEnabled) { // Set one or more IDs associated with the custom TTS voice your bot will use // The format of the string is one or more GUIDs separated by comma (no spaces). You get these GUIDs from // your custom TTS on the speech portal https://speech.microsoft.com/portal. - config.SetProperty(PropertyId.Conversation_Custom_Voice_Deployment_Ids, this.settings.RuntimeSettings.Profile.VoiceDeploymentIds); + config.SetProperty(PropertyId.Conversation_Custom_Voice_Deployment_Ids, profile.VoiceDeploymentIds); } - if (!string.IsNullOrEmpty(this.settings.RuntimeSettings.Profile.FromId)) + if (!string.IsNullOrEmpty(profile.FromId)) { // Set the from.id in the Bot-Framework Activity sent by this tool. // from.id field identifies who generated the activity, and may be required by some bots. // See https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-activity.md // for Bot Framework Activity schema and from.id. - config.SetProperty(PropertyId.Conversation_From_Id, this.settings.RuntimeSettings.Profile.FromId); + config.SetProperty(PropertyId.Conversation_From_Id, profile.FromId); } - if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.LogFilePath)) + if (!string.IsNullOrWhiteSpace(profile.LogFilePath)) { // Speech SDK has verbose logging to local file, which may be useful when reporting issues. // Supply the path to a text file on disk here. By default no logging happens. - config.SetProperty(PropertyId.Speech_LogFilename, this.settings.RuntimeSettings.Profile.LogFilePath); + config.SetProperty(PropertyId.Speech_LogFilename, profile.LogFilePath); } if (hasUrlOverride) { // For prototyping new Direct Line Speech channel service feature, a custom service URL may be // provided by Microsoft and entered in this tool. - config.SetProperty("SPEECH-Endpoint", this.settings.RuntimeSettings.Profile.UrlOverride); + config.SetProperty("SPEECH-Endpoint", profile.UrlOverride); } - if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ProxyHostName) && - !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ProxyPortNumber) && - int.TryParse(this.settings.RuntimeSettings.Profile.ProxyPortNumber, out var proxyPortNumber)) + if (!string.IsNullOrWhiteSpace(profile.ProxyHostName) && + !string.IsNullOrWhiteSpace(profile.ProxyPortNumber) && + int.TryParse(profile.ProxyPortNumber, out var proxyPortNumber)) { // To funnel network traffic via a proxy, set the host name and port number here - config.SetProxy(this.settings.RuntimeSettings.Profile.ProxyHostName, proxyPortNumber, string.Empty, string.Empty); + config.SetProxy(profile.ProxyHostName, proxyPortNumber, string.Empty, string.Empty); } // If a the DialogServiceConnector object already exists, destroy it first @@ -317,15 +341,15 @@ private void InitSpeechConnector() // Open a connection to Direct Line Speech channel this.connector.ConnectAsync(); - if (this.settings.RuntimeSettings.Profile.CustomSpeechEnabled) + if (profile.CustomSpeechEnabled) { - this.customSpeechConfig = new CustomSpeechConfiguration(this.settings.RuntimeSettings.Profile.CustomSpeechEndpointId); + this.customSpeechConfig = new CustomSpeechConfiguration(profile.CustomSpeechEndpointId); } - if (this.settings.RuntimeSettings.Profile.WakeWordEnabled) + if (profile.WakeWordEnabled) { // Configure wake word (also known as "keyword") - this.activeWakeWordConfig = new WakeWordConfiguration(this.settings.RuntimeSettings.Profile.WakeWordPath); + this.activeWakeWordConfig = new WakeWordConfiguration(profile.WakeWordPath); this.connector.StartKeywordRecognitionAsync(this.activeWakeWordConfig.WakeWordModel); } } diff --git a/clients/csharp-wpf/VoiceAssistantClient/Settings/ConnectionProfile.cs b/clients/csharp-wpf/VoiceAssistantClient/Settings/ConnectionProfile.cs index e9119cc3..370b6560 100644 --- a/clients/csharp-wpf/VoiceAssistantClient/Settings/ConnectionProfile.cs +++ b/clients/csharp-wpf/VoiceAssistantClient/Settings/ConnectionProfile.cs @@ -5,9 +5,11 @@ namespace VoiceAssistantClient.Settings { public class ConnectionProfile { - public string SubscriptionKey { get; set; } + public string SubscriptionKey { get; set; } + + public string AuthorizationToken { get; set; } - public string SubscriptionKeyRegion { get; set; } + public string SubscriptionRegion { get; set; } public string CustomCommandsAppId { get; set; } diff --git a/clients/csharp-wpf/VoiceAssistantClient/SettingsDialog.xaml b/clients/csharp-wpf/VoiceAssistantClient/SettingsDialog.xaml index eae95261..62671600 100644 --- a/clients/csharp-wpf/VoiceAssistantClient/SettingsDialog.xaml +++ b/clients/csharp-wpf/VoiceAssistantClient/SettingsDialog.xaml @@ -56,23 +56,26 @@