예제 #1
0
        /// <summary>
        /// 停止回答(沙勿略问我)
        /// </summary>
        public static void StopAnswer()
        {
            string retString = VoiceManage.rec_result;

            u.M2P_Answer_Panel.transform.GetChild(2).gameObject.GetComponent <UILabel>().text = retString;
            mt.AnswerAnalysis = true;
            if (retString != "")
            {
                string HayStack  = retString;
                Regex  r         = new Regex(@"[a-zA-Z]+");
                Match  m         = r.Match(HayStack);
                string answerStr = m.Value.ToUpper().Trim();
                string Needle    = tempAnswer[curNo - 1].CorrectAnswer;
                if (answerStr.Equals(Needle) || Needle.Contains(answerStr) && answerStr != "")
                {
                    animName  = AnimationControl.GetAnimationClipName(CharacterAction.Right);
                    content   = "恭喜你,回答正确";
                    voicename = "correct";
                    u.M2P_Answer_Panel.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = "回答正确";
                }
                else
                {
                    if (KeywordMatch.GetResultByKeywordMatch(HayStack, mt.AnswerList))
                    {
                        animName  = AnimationControl.GetAnimationClipName(CharacterAction.Right);
                        content   = "恭喜你,回答正确";
                        voicename = "correct";
                        u.M2P_Answer_Panel.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = "回答正确";
                    }
                    else
                    {
                        animName  = AnimationControl.GetAnimationClipName(CharacterAction.Wrong);
                        content   = "很遗憾,回答错误,正确答案是" + Needle;
                        voicename = "wrong";
                        u.M2P_Answer_Panel.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = "回答错误";
                    }
                }
            }
            else
            {
                animName  = AnimationControl.GetAnimationClipName(CharacterAction.Thinking);
                content   = "抱歉,您说了什么,我没有听清";
                voicename = "sorry";
                u.M2P_Answer_Panel.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = "抱歉,您说了什么,我没有听清";
            }
            Thread thread_analysis = new Thread(new ThreadStart(playVoice));

            thread_analysis.IsBackground = true;
            thread_analysis.Start();
        }
예제 #2
0
        /// <summary>
        /// 我问沙勿略模式
        /// </summary>
        public static void P2MMode(NAudioRecorder n)
        {
            canDistinguish = false;
            if (FlowManage.waveOutDevice != null)
            {
                FlowManage.waveOutDevice.Dispose();
                FlowManage.waveOutDevice = null;
            }
            if (FlowManage.audioFileReader != null)
            {
                FlowManage.audioFileReader.Close();
                FlowManage.audioFileReader = null;
            }
            if (VoiceManage.ask_rec_result == string.Empty || VoiceManage.ask_rec_result == null)
            {
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(1).gameObject.SetActive(true);
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = "对不起,我没有听清您说的话!可以再说一次吗?";
                content           = "对不起,我没有听清您说的话!可以再说一次吗?";
                voicename         = "answer";
                mt.FinishedAnswer = true;
                //mt.isFinished = true;
            }
            else
            {
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(1).gameObject.SetActive(true);
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = VoiceManage.ask_rec_result;
                Debug.Log("小沙正在思考中...");
                string answer_result = KeywordMatch.GetAnswerByKeywordMatch(VoiceManage.ask_rec_result, mt.BeforeAskList);//AIUI.HttpPost(AIUI.TEXT_SEMANTIC_API, "{\"userid\":\"test001\",\"scene\":\"main\"}", "text=" + Utils.Encode(VoiceManage.ask_rec_result));
                if (answer_result.Equals("抱歉,这个问题我还不知道,问答结束!"))
                {
                    answer_result = KeywordMatch.GetAnswerByKeywordMatch(VoiceManage.ask_rec_result, mt.AfterAskList);
                }
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(2).gameObject.SetActive(true);
                u.P2M_Ask_Panel.transform.GetChild(0).gameObject.transform.GetChild(2).gameObject.GetComponent <UILabel>().text = answer_result;
                content           = answer_result;
                voicename         = "answer";
                mt.FinishedAnswer = true;
                if (answer_result.Equals("抱歉,这个问题我还不知道,问答结束!"))
                {
                    XmlDocument    xml  = new XmlDocument();
                    XmlDeclaration decl = xml.CreateXmlDeclaration("1.0", "utf-8", null);
                    xml.AppendChild(decl);
                    XmlElement rootEle = xml.CreateElement("root");
                    xml.AppendChild(rootEle);
                    xml.Save(mt.record_path + "/record.xml");
                    DateTime dateTime = new DateTime();
                    dateTime = DateTime.Now;
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(Application.dataPath + "/Resources/Question/record.xml");
                    XmlNode    root = xmlDoc.SelectSingleNode("root");
                    XmlElement xe1  = xmlDoc.CreateElement("问题");
                    xe1.SetAttribute("内容", VoiceManage.ask_rec_result);
                    xe1.SetAttribute("时间", dateTime.ToString());
                    root.AppendChild(xe1);
                    xmlDoc.Save(Application.dataPath + "/Resources/Question/record.xml");
                    mt.FinishedAnswer = false;
                    VoiceManage.StopSpeech();
                }
            }
            Thread thread_answer = new Thread(new ThreadStart(playVoice));

            thread_answer.IsBackground = true;
            thread_answer.Start();
            //结束界面
            //进入唤醒状态
        }