// Handler for the SessionCompleted event on the Browser object. // This implementation writes the values returned by the VoiceXML dialog to the console. private void HandleSessionCompleted(object sender, SessionCompletedEventArgs e) { _waitForSessionCompleted.Set(); VoiceXmlResult result = e.Result; String cityOffset = result.Namelist["CityOffset"].ToString(); String utterance = result.Namelist["CityOffset$.utterance"].ToString(); String confidence = result.Namelist["CityOffset$.confidence"].ToString(); String requestedTime = result.Namelist["timeAtRequestedCity"].ToString(); Console.WriteLine("Returned semantic result: " + cityOffset); Console.WriteLine("Utterance: " + utterance); Console.WriteLine("Confidence: " + confidence); Console.WriteLine("Requested time: " + requestedTime); }
// Handler for the SessionCompleted event on the Browser object. // This implementation writes the values returned by the VoiceXML dialog to the console. private void HandleSessionCompleted(object sender, SessionCompletedEventArgs e) { Console.WriteLine("VXML HandleSessionCompleted."); VoiceXmlResult result = e.Result; if (e.Result != null && e.Result.Namelist != null) { string levelName = string.Empty; int choice = 0; var selection = result.Namelist["menu"].ToString(); Console.WriteLine("selected menu " + selection); currentLevel++; levelName = selection; if (currentLevel == 0) { if (int.TryParse(selection, out choice)) { var topLevels = parser.TopLevelMenuOptions(); var option = topLevels.Where(opt => opt.Id.Equals(selection, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); levelName = option.Name; } PlayMenu(levelName); selectedOptions.Insert(currentLevel, levelName); } else if (currentLevel == 1) { if (int.TryParse(selection, out choice)) { var subLevels = parser.SubOptions(selectedOptions[0]); var option = subLevels.Where(opt => opt.Id.Equals(selection, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); levelName = option.Name; } selectedOptions.Insert(currentLevel, levelName); waitForMenuInput.Set(); } } else { waitForMenuInput.Set(); } }
/// <summary> /// Run the browser /// </summary> private void RunBrowser() { InitializeVoiceXmlBrowser(); //If the start page has not been assigned, fail with appropriate message box. //More robust error checking is left as an exercise to the user. SetStartPage(); if (startPage == null) { MessageBox.Show(noUriError, errorInUri, MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (asyncRB.Checked) { //Associate the avCall with the VXML browser object. voiceXmlBrowser.SetAudioVideoCall(currentCall); //Calling RunAsync on the browser object will cause the VXML browser page to execute on the associated AVCall. //Note, the Async model used here is not the Begin/End type prevalent elsewhere in UCMA. voiceXmlBrowser.RunAsync(startPage, null); } else { //This is the synchronous case //Disable the buttons until the page has finished running. EnableButtons(false); //Associate the avCall with the VXML browser object. voiceXmlBrowser.SetAudioVideoCall(currentCall); // Start running the page against the current call synchronously VoiceXmlResult vr = voiceXmlBrowser.Run(startPage, null); //After run completes, re-enable the buttons. EnableButtons(true); } }