[HttpPost] // POST /voice public ActionResult SelectColorCallAnswered(CallStatusCallback callStatusCallback) { // Create an empty PerCL script container PerCLScript script = new PerCLScript(); // Verify call is in the InProgress state if (callStatusCallback.getDialCallStatus == ECallStatus.InProgress) { // Create PerCL get speech script (see grammar file content below) string actionUrl = AppUrl + "/voice/SelectColorDone"; string grammarFile = AppUrl + "/grammars/FreeClimbColor.xml"; GetSpeech getSpeech = new GetSpeech(actionUrl, grammarFile); // Set location and type of grammar as well as the grammar rule getSpeech.setGrammarType(EGrammarType.Url); getSpeech.setGrammarRule("FreeClimbColor"); // Create PerCL say script with US English as the language Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); // Set prompt for color selection say.setText("Please select a color. Select green, red or yellow."); // Add PerCL say script to PerCL get speech prompt list getSpeech.setPrompts(say); // Add PerCL get speech script to PerCL container script.Add(getSpeech); } // Convert PerCL container to JSON and append to response return(Content(script.toJson(), "application/json")); }
public void GetSpeechNoPromptsTest() { GetSpeech getSpeech = new GetSpeech("http://foo.com", "DIG1"); getSpeech.setGrammarType(EGrammarType.BuiltIn); string json = getSpeech.toJson(); Assert.IsNotNull(json); Assert.AreEqual(json, "{\"GetSpeech\":{\"actionUrl\":\"http://foo.com\",\"grammarFile\":\"DIG1\",\"grammarType\":\"BUILTIN\",\"prompts\":[]}}"); }
public void GetSpeechPromptsTest() { GetSpeech getSpeech = new GetSpeech("http://foo.com", "DIG1"); getSpeech.setGrammarType(EGrammarType.BuiltIn); Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); say.setText("Test"); getSpeech.setPrompts(say); string json = getSpeech.toJson(); Assert.IsNotNull(json); Assert.AreEqual(json, "{\"GetSpeech\":{\"actionUrl\":\"http://foo.com\",\"grammarFile\":\"DIG1\",\"grammarType\":\"BUILTIN\",\"prompts\":[{\"Say\":{\"text\":\"Test\",\"language\":\"en-US\"}}]}}"); }