Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            // General variables
            DateTime            timeStart = DateTime.Now;
            string              path      = context.Request.PhysicalApplicationPath;
            string              userid    = HttpContext.Current.User.Identity.Name;
            Tuple <string, int> imageInfo = new Tuple <string, int>("", 2);
            string              page      = "";

            // Variables important to the speaker's state
            string     audioFile         = path + "data\\userAudio\\blob.wav";
            string     transcript        = "";
            string     dialogueAct       = "";
            int        speakerSpoke      = 0;
            List <int> problemStep       = new List <int>();                                                                // [0] is problem, [1] is the step, and [2] is the image key loaded for this step, [3] is the answer pattern
            int        sessionid         = 1;                                                                               // ************************* FIX THIS ********
            int        nextstepanswerkey = 0;

            // Variables important to Nico's state
            Tuple <string, int, string> nicoResponse;                                                                           // string => Nico's response, int is the movement code, string contains whether Nico is 'answering', 'confirming', or 'not answering'

            try
            {
                problemStep = SQLProblemStepTracker.ReadProbStep(userid);                                                   // Get current step
                int    problem          = problemStep[0];
                int    step             = problemStep[1];
                int    probImg          = problemStep[2];
                int    answerKey        = problemStep[3];
                int    numAutoResponses = problemStep[5];
                int    numturns         = problemStep[6];
                string clickstep        = "none";
                int    newanswer        = 0;

/*
 *              if (step == 0)
 *              {
 *                  step = 1;
 *              }
 */
                transcript = context.Request.Params["transcript"];    // Get transcript (if there is one)
                page       = context.Request.Params["page_loc"];

                if (context.Request.Files.Count > 0)                                                                       // Write out audio file (if it's there)
                {
                    HttpFileCollection files = context.Request.Files;
                    //audioFile = writeFile(files, path, userid, timeStart);
                }
                if (transcript == "problem start")
                {
                    speakerSpoke = 0;
                    clickstep    = "problem start";
                    step         = 1;
                }
                else if (transcript == "no response")
                {
                    speakerSpoke      = 0;
                    clickstep         = "null";
                    numAutoResponses += 1;
                    transcript        = "Triggered Speech " + numAutoResponses.ToString();
                }
                else if (transcript == "HELLO FIRST TIME")
                {
                    speakerSpoke = 0;
                    clickstep    = "hello nico start";
                }
                else if ((transcript != "") && (transcript != null))                                                             // Is there a transcript? If there is get the speaker's dialogue act
                {
                    dialogueAct  = estimateDialogueAct(transcript);
                    speakerSpoke = 1;                                                                                           // Set that the speaker actually spoke this turn
                }
                else
                {
                    speakerSpoke = 2;
                    transcript   = "transcript empty or null";
                }

                nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, speakerSpoke, transcript, timeStart, page, userid, audioFile);     // Generate and initiate Nico's response
                SQLUserState.UpdateSpeakerState(userid, dialogueAct, transcript, speakerSpoke, problemStep, timeStart, clickstep, numAutoResponses); // Write out speaker state info
                SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, timeStart);                                                          // Write out Nico's state info & update problem/step


                // Nico response: string => Nico's response, int is the movement code, the boolean indicates whether Nico answered the step
                // To update the step, we check if Nico answered the question.

                numturns += 1;
                if (nicoResponse.Item3 == "answering")
                {
                    nextstepanswerkey = SQLProblemStepTracker.CalculateNewAnswerKey(1, answerKey, step, userid);                // Passing 1 as first argument because Nico DID answer this step
                    newanswer         = step;
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, step, probImg, nextstepanswerkey, newanswer, numAutoResponses, numturns);
                }
                else
                {
                    nextstepanswerkey = answerKey;                                                                                 // current answer key
                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, step, probImg, nextstepanswerkey, newanswer, numAutoResponses, numturns);
                }
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "DialogueEngine.ashx.cs", 0, userid);
            }

            string transResponse = "Saved User Wav File!";

            context.Response.ContentType = "audio/wav";
            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            context.Response.AppendHeader("Access-Control-Allow-Headers", "x-requested-with");
            context.Response.Write(transResponse);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            string userid = HttpContext.Current.User.Identity.Name;

            try
            {
                int    sessionid = 1;
                int    maxprobs  = 9;
                string page      = "ProblemPage";


                List <int> problemStep      = SQLProblemStepTracker.ReadProbStep(userid);
                int        problem          = problemStep[0];
                int        nextproblem      = problem + 1;
                int        step             = problemStep[1];
                int        nextStep         = step + 1;
                int        priorStep        = step - 1;
                int        problemimgkey    = problemStep[2];
                int        answerKey        = problemStep[3];
                int        newanswer        = problemStep[4];
                int        numautoresponses = problemStep[5];
                int        numturns         = problemStep[6];



                if (step == 0)
                {
                    step     = 1;
                    nextStep = 2;
                }

                // Variables important to Nico's state
                Tuple <string, int, string> nicoResponse;                                                                      // string => Nico's response, int is the movement code, string is whether nico is answering
                string   path      = HttpRuntime.AppDomainAppPath;
                string   useraudio = path + "data\\userAudio\\blob.wav";
                DateTime now       = DateTime.Now;
                string   clickstep = "";

                string response = "continue";

                string clicked = context.Request.Params["button_info"];
                switch (clicked)
                {
                case "next":
                    problemStep[1] = nextStep;
                    newanswer      = 0;
                    numturns       = 0;

                    clickstep    = "step_" + step.ToString() + "_" + nextStep.ToString();
                    nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "next step", now, page, userid, useraudio);
                    SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                    SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step

                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, nextStep, problemimgkey, answerKey, newanswer, numautoresponses, numturns);

                    break;

                case "prior":
                    problemStep[1] = priorStep;
                    newanswer      = 0;
                    numturns       = 0;

                    clickstep    = "step_" + step.ToString() + "_" + priorStep.ToString();
                    nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "prior step", now, page, userid, useraudio);
                    SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                    SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step

                    SQLProblemStepTracker.UpdateProbStep(userid, sessionid, problem, priorStep, problemimgkey, answerKey, newanswer, numautoresponses, numturns);

                    break;

                case "problem":
                    if (nextproblem > maxprobs)
                    {
                        response = "end of session";
                    }
                    else
                    {
                        step           = 1;
                        answerKey      = 1;
                        newanswer      = 0;
                        problemStep[0] = nextproblem;
                        numturns       = 0;

                        clickstep = "problem_" + problem.ToString() + "_" + nextproblem.ToString();

                        nicoResponse = ResponseGeneration.NicoResponse(path, problemStep, 0, "problem start", now, page, userid, useraudio);
                        SQLUserState.UpdateSpeakerState(userid, "", "", 0, problemStep, now, clickstep, numautoresponses);              // Write out speaker state info
                        SQLNicoState.UpdateNicoState(userid, nicoResponse, problemStep, now);                                           // Write out Nico's state info & update problem/step


                        SQLProblemStepTracker.UpdateProbStep(userid, sessionid, nextproblem, step, problemimgkey, answerKey, newanswer, numautoresponses, numturns);
                    }

                    break;

                default:

                    break;
                }

                context.Response.ContentType = "text/HTML";
                context.Response.Write(response);
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.ToString(), "UpdateStep.ashx.cs", 0, userid);
            }
        }