/// <summary> /// Initializes the connection to the Bot. /// </summary> /// <param name="settings">Application settings object, built from the input JSON file supplied as run-time argument.</param> public void InitConnector(AppSettings settings) { DialogServiceConfig config; this.BotReplyList = new List <BotReply>(); this.stopWatch = new Stopwatch(); this.appsettings = settings; if (!string.IsNullOrWhiteSpace(this.appsettings.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. // - The Azure region of the subscription key(e.g. "westus"). config = CustomCommandsConfig.FromSubscription(this.appsettings.CustomCommandsAppId, this.appsettings.SpeechSubscriptionKey, this.appsettings.SpeechRegion); } 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.appsettings.SpeechSubscriptionKey, this.appsettings.SpeechRegion); } if (this.appsettings.SpeechSDKLogEnabled) { // Speech SDK has verbose logging to local file, which may be useful when reporting issues. config.SetProperty(PropertyId.Speech_LogFilename, $"{this.appsettings.OutputFolder}SpeechSDKLog-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.CurrentCulture)}.log"); } if (!string.IsNullOrWhiteSpace(this.appsettings.SRLanguage)) { // Set the speech recognition language. If not set, the default is "en-us". config.Language = this.appsettings.SRLanguage; } if (!string.IsNullOrWhiteSpace(this.appsettings.CustomSREndpointId)) { // 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.appsettings.CustomSREndpointId, 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"); } else { // If a custom speech endpoint is not specified, keyword verification is set // according to the default or configured settings. config.SetProperty("KeywordConfig_EnableKeywordVerification", this.appsettings.KeywordVerificationEnabled.ToString().ToLower()); } if (!string.IsNullOrWhiteSpace(this.appsettings.CustomVoiceDeploymentIds)) { // 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.appsettings.CustomVoiceDeploymentIds); } this.timeout = this.appsettings.Timeout; if (!string.IsNullOrWhiteSpace(this.appsettings.KeywordRecognitionModel)) { this.kwsTable = KeywordRecognitionModel.FromFile(this.appsettings.KeywordRecognitionModel); } if (this.appsettings.SetPropertyId != null) { foreach (KeyValuePair <string, JToken> setPropertyIdPair in this.appsettings.SetPropertyId) { config.SetProperty(setPropertyIdPair.Key, setPropertyIdPair.Value.ToString()); } } if (this.appsettings.SetPropertyString != null) { foreach (KeyValuePair <string, JToken> setPropertyStringPair in this.appsettings.SetPropertyString) { config.SetProperty(setPropertyStringPair.Key.ToString(CultureInfo.CurrentCulture), setPropertyStringPair.Value.ToString()); } } if (this.appsettings.SetServiceProperty != null) { foreach (KeyValuePair <string, JToken> setServicePropertyPair in this.appsettings.SetServiceProperty) { config.SetServiceProperty(setServicePropertyPair.Key.ToString(CultureInfo.CurrentCulture), setServicePropertyPair.Value.ToString(), ServicePropertyChannel.UriQueryParameter); } } if (this.appsettings.RealTimeAudio) { config.SetProperty("SPEECH-AudioThrottleAsPercentageOfRealTime", "100"); config.SetProperty("SPEECH-TransmitLengthBeforeThrottleMs", "0"); } if (this.connector != null) { // Then dispose the object this.connector.Dispose(); this.connector = null; } if (this.appsettings.PushStreamEnabled) { this.pushAudioInputStream = AudioInputStream.CreatePushStream(); this.audioConfig = AudioConfig.FromStreamInput(this.pushAudioInputStream); } else { config.SetProperty("KeywordConfig_EnableKeywordVerification", "false"); this.audioConfig = AudioConfig.FromStreamInput(GlobalPullStream.FilePullStreamCallback); } this.connector = new DialogServiceConnector(config, this.audioConfig); if (this.appsettings.BotGreeting) { // Starting the timer to calculate latency for Bot Greeting. this.stopWatch.Restart(); } this.AttachHandlers(); }
/// <summary> /// Initializes a new instance of the <see cref="DialogResult"/> class. /// </summary> /// <param name="settings">Application settings.</param> /// <param name="dialogID">Unique dialog ID.</param> /// <param name="description">Description of the dialog.</param> public DialogResult(AppSettings settings, string dialogID, string description) { this.appSettings = settings; this.DialogID = dialogID; this.Description = description; }