Esempio n. 1
0
 /* Method: CallLUIS
  * Usage: To call LUIS NLU to get the intent from the output text received from ASR
  * Parameters: ASRoutput */
 public LuisJson CallLUIS(string ASROutput)
 {
     //ASR call which gives a string ;
     try
     {
         Luis LuisObject = new Luis();
         LuisJson objResponse = LuisObject.getLUISResponse(ASROutput);
         return objResponse;
     }
     catch (Exception e)
     {
         String strTextToWrite = DateTime.Now.ToString() + "StartHere.CallLUIS Exception: " + e.Message;
         File.AppendAllText(ASRFile, strTextToWrite + Environment.NewLine);
         return null;
     }
 }
Esempio n. 2
0
 /* Method: getLUISResponse
 * Usage: Calls LUIS NLU to get the intent from the output text received from ASR
 * Parameters: ASRoutput */
 public LuisJson getLUISResponse(String ASROutput)
 {
     try
     {
         string   url         = $"https://api.projectoxford.ai/luis/v2.0/apps/6d9801a6-0dda-4026-a5d4-34f05943c899?subscription-key=e0f547ffc7554e9dbb2de915064f482c&q={ASROutput}";
         var      syncClient  = new WebClient();
         var      content     = syncClient.DownloadString(url);
         String   strResponse = content.ToString();
         LuisJson lstResponse = new LuisJson();
         lstResponse = JsonConvert.DeserializeObject <LuisJson>(strResponse) as LuisJson;
         return(lstResponse);
     }
     catch (Exception e)
     {
         String ASRFile        = @"C:\test files\ASR test files\\Test01.txt";
         String strTextToWrite = DateTime.Now.ToString() + "Luis.getLUISResponse Exception: " + e.Message;
         File.AppendAllText(ASRFile, strTextToWrite + Environment.NewLine);
         return(null);
     }
 }
Esempio n. 3
0
        public String[] Process(String[] strAudioFile)
        {
            String[] lstResponse;
            String[] strTranscribedText;
            try
			{
                strTranscribedText = TranscribeAsync.Main(strAudioFile);
                if (strTranscribedText == null)
                {
                    lstResponse = new String[1];
                    lstResponse[0] = Dialogues.defaultText;
                    //callTTS(Dialogues.defaultText);
                    goto end;
                }
                strTranscribedText[0] = String.Join(".", strTranscribedText);
                String s = strTranscribedText[0].TrimEnd('.');
                strTranscribedText[0] = strTranscribedText[0].TrimEnd('.');
                String strTextToWrite = DateTime.Now.ToString() + " " + strTranscribedText[0];
                File.AppendAllText(ASRFile, strTextToWrite + Environment.NewLine);
                /*redoLUIS:*/
                LuisJson objResponse = CallLUIS(strTranscribedText[0]);
                int nArraySize = objResponse.entities.Count == 0 ? 1 : objResponse.entities.Count;
                lstResponse = new String[nArraySize];
                if (objResponse.topScoringIntent.score < 0.5)
                {
                    strUtterance = strTranscribedText[0];
                    //lstResponse[0] = Dialogues.explicitGrounding + strUtterance + "?";
                    lstResponse[0] = getDefaultText();
                    bExplicitGround = true;
                    if (bRecipes)
                    {
                        callTTS(Dialogues.defaultRecipe);
                        lstResponse = lstRecipes;
                    }
                    goto end;
                }
                else if (objResponse.entities.Count == 0 && objResponse.topScoringIntent.intent == "listofIngredients")
                {
                    strUtterance = strTranscribedText[0];
                    //lstResponse[0] = Dialogues.explicitGrounding + strUtterance + "?";
                    lstResponse[0] = getDefaultText();
                    bExplicitGround = true;
                    if (bRecipes)
                    {
                        lstResponse = lstRecipes;
                        callTTS(Dialogues.defaultRecipe);
                    }
                    goto end;
                }
                //Below block calls the TTS with the input based on the intent
                switch (objResponse.topScoringIntent.intent)
                {
                    case "GreetingS":
                    case "Restart":
                        //callTTS(Dialogues.Greet1);
                        lstResponse[0] = Dialogues.Greet1;
                        break;
                    case "Repeat":
                    case "listofIngredients":
                        #region ingredient
                        bIngredients = true;
                        if (lstIngredients == null)
                            lstIngredients = new List<string>();
                        if (objResponse.entities.Count > 1)
                        {
                            for (int i = 0; i < objResponse.entities.Count; i++)
                            {

                                if (objResponse.entities[i].type == "Ingredients")
                                    lstIngredients.Add(objResponse.entities[i].entity);
                            }
                            lstResponse[0] = "You have " + String.Join(", ", lstIngredients) + ". " + Dialogues.moreIngredient;
                            //callTTS(Dialogues.moreIngredient);
                        }
                        else
                        {
                            lstIngredients.Add(objResponse.entities[0].entity);
                            switch (nGroundingCt)
                            {
                                case 0:
                                    lstResponse[0] = Dialogues.nextIngredient0;
                                    //callTTS(Dialogues.nextIngredient0);
                                    nGroundingCt++;
                                    break;
                                case 1:
                                    lstResponse[0] = Dialogues.nextIngredient1;
                                    //callTTS(Dialogues.nextIngredient1);
                                    nGroundingCt++;
                                    break;
                                case 2:
                                    lstResponse[0] = Dialogues.nextIngredient2;
                                    //callTTS(Dialogues.nextIngredient2);
                                    nGroundingCt++;
                                    break;
                                case 3:
                                    lstResponse[0] = Dialogues.nextIngredient3;
                                    //callTTS(Dialogues.nextIngredient3);
                                    break;
                                default:
                                    lstResponse[0] = Dialogues.nextIngredient3;
                                    nGroundingCt++;
                                    nGroundingCt = 0;
                                    goto end;
                            }
                            // lstResponse
                            //lstResponse = getRecipeNames(lstIngredients);
                        }
                        break;
                    #endregion
                    case "negativeAck":
                        String strIngredientList = "";
                        if (bIngredients)
                        {
                            strIngredientList = String.Join(",", lstIngredients.ToArray());
                            strIngredientList = Dialogues.Ingredients + " " + strIngredientList;
                            strRecipeList = getRecipeNames(strIngredientList);
                            if (lstRecipes == null)
                                lstRecipes = new String[strRecipeList.Count() + 1];
                            lstResponse = new String[strRecipeList.Count() + 1];
                            lstResponse[0] = strIngredientList + " " + Dialogues.recipeHeader;
                            for (int i = 0; i < strRecipeList.Count(); i++)
                            {
                                lstResponse[i + 1] = (i + 1).ToString() + ". " + strRecipeList[i];
                            }
                            lstRecipes = lstResponse;
                            bRecipes = true;
                        }
                        else if (bExplicitGround)
                        {

                        }
                        break;
                    case "RecipeNumber":
                        #region recipeNum
                        lstIngredients = new List<string>();
                        if (objResponse.topScoringIntent.score > 0.5)
                        {
                            String strRecipeNum = objResponse.entities[0].entity;
                            Spoonacular objSpoon = new Spoonacular();
                            String[] lstSteps;
                            switch (strRecipeNum)
                            {
                                case "first":
                                case "one":
                                case "1st":
                                case "1":
                                    lstSteps = objSpoon.getInstructions(lstRecipeID[0], strRecipeList[0]);
                                    lstResponse = lstSteps;
                                    //callTTS(Dialogues.recipeInstructions);
                                    break;
                                case "second":
                                case "two":
                                case "2nd":
                                case "2":
                                    lstSteps = objSpoon.getInstructions(lstRecipeID[1], strRecipeList[1]);
                                    lstResponse = lstSteps;
                                    //callTTS(Dialogues.recipeInstructions);
                                    break;
                                case "third":
                                case "three":
                                case "3rd":
                                case "3":
                                    lstSteps = objSpoon.getInstructions(lstRecipeID[2], strRecipeList[2]);
                                    lstResponse = lstSteps;
                                    //callTTS(Dialogues.recipeInstructions);
                                    break;
                                case "fourth":
                                case "four":
                                case "4th":
                                case "4":
                                    lstSteps = objSpoon.getInstructions(lstRecipeID[3], strRecipeList[3]);
                                    lstResponse = lstSteps;
                                    //callTTS(Dialogues.recipeInstructions);
                                    break;
                                case "fifth":
                                case "five":
                                case "5th":
                                case "5":
                                case "last":
                                    lstSteps = objSpoon.getInstructions(lstRecipeID[4], strRecipeList[4]);
                                    lstResponse = lstSteps;
                                    //callTTS(Dialogues.recipeInstructions);
                                    break;
                            }
                            bRecipes = false;
                        }
                        else
                        {
                            lstResponse[0] = getDefaultText();
                        }
                        lstIngredients = new List<string>();
                        strRecipeList = new String[5];
                        break;
                    #endregion
                    //case "positiveAck":
                    //    if (bExplicitGround)
                    //    {
                    //        strTranscribedText[0] = strUtterance;
                    //        strUtterance = "";
                    //        bExplicitGround = false;
                    //        goto redoLUIS;
                    //    }
                    //    break;
                    default:
                        lstResponse[0] = getDefaultText();
                        if (bRecipes)
                        {
                            lstResponse = lstRecipes;
                            callTTS(Dialogues.defaultRecipe);
                        }
                        break;
                }
            end: return lstResponse;
            }
            catch (Exception e)
            {
                lstResponse = new String[1];
                lstResponse[0] = Dialogues.defaultText.ToString();
                String strTextToWrite = DateTime.Now.ToString() + "StartHere.Process Exception: " + e.Message;
                File.AppendAllText(ASRFile, strTextToWrite + Environment.NewLine);
                return lstResponse;
            }
        }