コード例 #1
0
    private void OnRecognize(SpeechRecognitionEvent result, Dictionary <string, object> customData)
    {
        if (result != null && result.results.Length > 0)
        {
            foreach (var res in result.results)
            {
                foreach (var alt in res.alternatives)
                {
                    string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence);
                    Log.Debug("ExampleStreaming.OnRecognize()", text);

                    if (text.Contains("Final"))
                    {
                        if (text.Contains("Control") || text.Contains("control"))
                        {
                            gm.SetActive(true);
                            ResultsField.text = text.Substring(0, text.Length - 14);
                            StartCoroutine(PauseRoutine());
                            if ((text.Contains("Display") || text.Contains("display")) && (text.Contains("ready") || text.Contains("Ready")))
                            {
                                controllerScript ss = hud.GetComponent <controllerScript>();
                                if (screen3 == null)
                                {
                                    screen3 = ss.CreateNewScreen();
                                }
                                else
                                {
                                    Ttext = "Screen already Present";
                                    ttss();
                                }
                            }

                            else if ((text.Contains("Display") || text.Contains("display")) && (text.Contains("destroy") || text.Contains("Destroy")))
                            {
                                controllerScript ss = hud.GetComponent <controllerScript>();
                                if (screen3 != null)
                                {
                                    ss.deleteScreen(screen3);
                                }
                                else
                                {
                                    Ttext = "Nothing to destroy";
                                    ttss();
                                }
                            }
                            else if ((text.Contains("fresh") || text.Contains("Refresh")))
                            {
                                if (screen2 != null)
                                {
                                    busy2 = 0;
                                    Material loading = Resources.Load("Resources/loading.mat", typeof(Material)) as Material;
                                    screen2.GetComponent <VideoPlayer>().Stop();
                                    MeshRenderer mr = screen2.GetComponent <MeshRenderer>();
                                    mr.material.color = Color.black;
                                    // screen2.SetActive(false);

                                    // screen2o.SetActive(true);
                                    // screen2o.transform.position = new Vector3(screen2o.transform.position.x, (float)(screen2o.transform.position.y + .2), screen2o.transform.position.z);
                                    //screen2.GetComponents<MeshRenderer>
                                }

                                if (screen1 != null)
                                {
                                    busy1 = 0;
                                    Material loading = Resources.Load("Resources/loading.mat", typeof(Material)) as Material;
                                    screen1.GetComponent <VideoPlayer>().Stop();
                                    MeshRenderer mr = screen1.GetComponent <MeshRenderer>();
                                    mr.material.color = Color.black;
                                    //screen1.SetActive(false);

                                    //screen1o.SetActive(true);
                                    // screen1o.transform.position = new Vector3(screen1o.transform.position.x, (float)(screen1o.transform.position.y  .2), screen1o.transform.position.z);
                                    //screen2.GetComponents<MeshRenderer>
                                }
                            }
                            else if ((text.Contains("what") || text.Contains("What")) && (text.Contains("this") || text.Contains("This")))
                            {
                                Classification cc = hud.GetComponent <Classification>();
                                cc.ProcessImage();
                            }
                            else if (text.Contains("Load") || text.Contains("load") || text.Contains("Lord") || text.Contains("lord"))
                            {
                                string url = "www." + "google" + ".com";
                                if (text.Contains("google") || text.Contains("goo"))
                                {
                                    url = "www." + "google" + ".com";
                                }
                                else if (text.Contains("apple") || text.Contains("apple"))
                                {
                                    url = "www." + "apple" + ".com";
                                }
                                else if (text.Contains("tcd") || text.Contains("trinity"))
                                {
                                    url = "www." + "tcd" + ".ie";
                                }
                                else if (text.Contains("vsense") || text.Contains("sense"))
                                {
                                    url = "v-sense.scss.tcd.ie";
                                }


                                if (screen3 != null)
                                {
                                    screen3.GetComponent <DisplayBehavior>().LoadWebsite(url);
                                    busy3 = 1;
                                }
                                else if (screen2 != null && busy2 == 0)
                                {
                                    Debug.Log("inside screen 2:");
                                    Debug.Log("busy2:" + busy2);
                                    Debug.Log("busy1:" + busy1);

                                    screen2.SetActive(true);
                                    screen2.GetComponent <WebsiteAPI>().LoadImage1(url);
                                    screen2o = GameObject.FindWithTag("screen2");
                                    screen2o.SetActive(false);
                                    //  screen2o.transform.position = new Vector3(screen2o.transform.position.x, (float)(screen2o.transform.position.y - .2), screen2o.transform.position.z);
                                    busy2 = 1;
                                }
                                else if (screen1 != null && busy1 == 0)
                                {
                                    Debug.Log("inside screen 1:");
                                    Debug.Log("busy2:" + busy2);
                                    Debug.Log("busy1:" + busy1);

                                    screen1.SetActive(true);
                                    screen1.GetComponent <WebsiteAPI>().LoadImage1(url);
                                    screen1o = GameObject.FindWithTag("screen1");
                                    screen1o.SetActive(false);
                                    // screen1o.transform.position = new Vector3(screen1o.transform.position.x, (float)(screen1o.transform.position.y - .2), screen1o.transform.position.z);
                                    busy1 = 1;
                                }
                            }
                            else if (text.Contains("video") || text.Contains("video") || text.Contains("radio"))
                            {
                                string url = "https://www.youtube.com/watch?v=TcMBFSGVi1c";
                                if (text.Contains("marvel") || text.Contains("capt") || text.Contains("mar"))
                                {
                                    url = "https://www.youtube.com/watch?v=0LHxvxdRnYc";
                                }
                                else if (text.Contains("avenger") || text.Contains("avg") || text.Contains("end") || text.Contains("game"))
                                {
                                    url = "https://www.youtube.com/watch?v=TcMBFSGVi1c";
                                }
                                else if (text.Contains("uri") || text.Contains("attack"))
                                {
                                    url = "https://www.youtube.com/watch?v=Cg8sbRFS3zU";
                                }
                                else if (text.Contains("ana") || text.Contains("bel"))
                                {
                                    url = "https://www.youtube.com/watch?v=tCXGJQYZ9JA";
                                }
                                else if (text.Contains("black") || text.Contains("pan"))
                                {
                                    url = "https://www.youtube.com/watch?v=gAEXKmfAFaE";
                                }

                                if (screen3 != null)
                                {
                                    screen3.GetComponent <DisplayBehavior>().LoadVideo(url);
                                    busy3 = 1;
                                }
                                else if (screen2 != null && busy2 == 0)
                                {
                                    screen2.SetActive(true);
                                    screen2.GetComponent <YouTubeAPI>().LoadVideo1(url);
                                    GameObject.FindWithTag("screen2").SetActive(false);
                                    busy2 = 1;
                                }
                                else if (screen1 != null && busy1 == 0)
                                {
                                    screen1.SetActive(true);
                                    screen1.GetComponent <YouTubeAPI>().LoadVideo1(url);
                                    GameObject.FindWithTag("screen1").SetActive(false);
                                    busy1 = 1;
                                }
                            }
                            else
                            {
                                integrator ii = GameObject.FindWithTag("agent").GetComponent <integrator>();
                                ii.SendText(text.Substring(7));
                            }
                        }
                    }
                }

                if (res.keywords_result != null && res.keywords_result.keyword != null)
                {
                    foreach (var keyword in res.keywords_result.keyword)
                    {
                        Log.Debug("ExampleStreaming.OnRecognize()", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time);
                    }
                }

                if (res.word_alternatives != null)
                {
                    foreach (var wordAlternative in res.word_alternatives)
                    {
                        Log.Debug("ExampleStreaming.OnRecognize()", "Word alternatives found. Start time: {0} | EndTime: {1}", wordAlternative.start_time, wordAlternative.end_time);
                        foreach (var alternative in wordAlternative.alternatives)
                        {
                            Log.Debug("ExampleStreaming.OnRecognize()", "\t word: {0} | confidence: {1}", alternative.word, alternative.confidence);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
 private void Start()
 {
     controller = GameObject.Find("MainController").GetComponent <controllerScript>();
     local      = GameObject.Find("GamePanel").GetComponent <localScript>();
     initializeEvents();
 }