コード例 #1
0
        void Update()
        {
            if (!settings_set)
            {
                buttons["MoveWithMe"].GetComponent <TextMesh>().text     = MoveWithMe ? "Captions move with you" : "Captions are fixed to world";
                buttons["AutoDistance"].GetComponent <TextMesh>().text   = (CaptionDistance == 0) ? "Automatic depth" : ("Fixed depth: " + CaptionDistance + "m");
                buttons["DepthDebug"].GetComponent <TextMesh>().text     = DepthDebug ? "Showing depth debug" : "Not showing depth debug";
                buttons["ShowCursor"].GetComponent <TextMesh>().text     = ShowCursor ? "Showing cursor" : "Not showing cursor";
                buttons["TextSize"].GetComponent <TextMesh>().text       = "Text size: " + (TextSize == 0 ? "small" : (TextSize == 1 ? "medium" : "large"));
                buttons["TextLines"].GetComponent <TextMesh>().text      = "Text lines: " + TextLines;
                buttons["TextLineLength"].GetComponent <TextMesh>().text = "Line length: " + TextLineLength + " characters";

                gameObject.GetComponent <TranslateToCamera>().EnableMovement = MoveWithMe;

                DepthObject.GetComponent <SpatialMappingRenderer>().enabled = DepthDebug;
                CursorVisual.transform.localScale = ShowCursor ? new Vector3(0.03f, 0.03f, 0.03f) : new Vector3(0.0f, 0.0f, 0.0f);

                settings_set = true;
            }


            InputModule.CursorStateEnum cursorState = CursorObject.GetComponent <InputModule.AnimatedCursor>().CursorState;
            if (cursorState == InputModule.CursorStateEnum.Interact || cursorState == InputModule.CursorStateEnum.InteractHover || cursorState == InputModule.CursorStateEnum.Select)
            {
                InputModule.IPointingSource thisistoocomplex;
                if (InputModule.FocusManager.Instance.TryGetSinglePointer(out thisistoocomplex))
                {
                    GameObject focused = InputModule.FocusManager.Instance.GetFocusedObject(thisistoocomplex);

                    if (captions.Count > 1)
                    {
                        for (int i = captions.Count - 1; i >= 0; i--)
                        {
                            GameObject o = captions[i];
                            if (o.GetComponent <GlassEarTagalong>().frozen&& focused == o)
                            {
                                o.GetComponent <GlassEarTagalong>().lastHoverTime = Time.time;
                            }
                        }
                    }

                    foreach (KeyValuePair <string, GameObject> b in buttons)
                    {
                        if (focused == b.Value)
                        {
                            b.Value.GetComponent <HighightControl>().HoverTime = Time.time;
                        }
                    }
                }
            }

            soundClassDisplay.GetComponent <TextMesh>().text = classString;

            pos = Microphone.GetPosition(null);

            // Avoid getting repeated data chunk
            if (pos < lastPos)
            {
                pos += 10 * RATE;
            }
            if (pos > lastPos + CHUNK)
            {
                micClip.GetData(sample, lastPos);
                lastPos = lastPos + CHUNK;
                if (lastPos > RATE * 10)
                {
                    lastPos -= RATE * 10;
                }
                byte[] barry = new byte[sample.Length * 2];
                FloatToByte(barry, sample);
                audioStream.Write(barry, 0, barry.Length);
            }


            float[] copyArr = new float[sample.Length];
            for (var i = 0; i < sample.Length; i++)
            {
                copyArr[i] = sample[i];
            }
            queue.Enqueue(copyArr);
            // Accumulate sound segment until reaching the specific length
            if (queue.Count >= 10)
            {
                for (var i = 0; i < 10; i++)
                {
                    copyArr = queue.Dequeue();
                    for (var j = 0; j < sample.Length; j++)
                    {
                        sampleClassification[j + CHUNK * i] = copyArr[j];
                    }
                }
                queue.Clear();

                // Send data to sound recognition server
                if (outstream != null && outstream.CanWrite)
                {
                    byte[] data = new byte[32000];
                    FloatToByte(data, sampleClassification);
                    outstream.Write(data, 0, data.Length);
                }

                // Get sound label
                while (outstream != null && outstream.DataAvailable)
                {
                    byte[] buf   = new byte[128];
                    int    bytes = outstream.Read(buf, 0, 128);
                    string label = System.Text.Encoding.UTF8.GetString(buf, 0, bytes);
                    if (label != "Unrecognized Sound" && label != "Speech")
                    {
                        outlst.AddLast(label);
                        classLabelLen++;
                        if (classLabelLen > 3)
                        {
                            outlst.RemoveFirst();
                        }
                        classString = "";
                        foreach (String o in outlst)
                        {
                            classString += o + "\n";
                        }
                    }
                }
            }

            lock (threadLocker)
            {
                if (intermString.Length > 0)
                {
                    OnPacket_interm(intermString);
                    intermString = "";
                }
                if (curString.Length > 0)
                {
                    OnPacket(curString);
                    curString = "";
                }
            }
        }
コード例 #2
0
        void Update()
        {
#if UNITY_EDITOR
            if ((Time.time - last_fake_message_time) > 1)
            {
                last_fake_message_time = Time.time;

                string next_packet = last_packet;

                int nextword = UnityEngine.Random.Range(2, 6);

                while (nextword > 0)
                {
                    nextword--;
                    next_packet = next_packet + "a";
                }

                next_packet = next_packet + "\n";
                nextword    = UnityEngine.Random.Range(2, 6);

                while (nextword > 0)
                {
                    nextword--;
                    next_packet = next_packet + "w";
                }

                if (next_packet.Length > 250)
                {
                    next_packet = next_packet.Substring(next_packet.Length - 250);
                }

                OnPacket(next_packet);
            }
#else
            if (incoming_packet_counter > processed_incoming_packet_counter)
            {
                processed_incoming_packet_counter = incoming_packet_counter;
                OnPacket(incoming_packet);
            }
#endif

            if (!settings_set)
            {
                buttons["MoveWithMe"].GetComponent <TextMesh>().text     = MoveWithMe ? "Captions move with you" : "Captions are fixed to world";
                buttons["AutoDistance"].GetComponent <TextMesh>().text   = (CaptionDistance == 0) ? "Automatic depth" : ("Fixed depth: " + CaptionDistance + "m");
                buttons["DepthDebug"].GetComponent <TextMesh>().text     = DepthDebug ? "Showing depth debug" : "Not showing depth debug";
                buttons["TextSize"].GetComponent <TextMesh>().text       = "Text size: " + (TextSize == 0 ? "small" : (TextSize == 1 ? "medium" : "large"));
                buttons["TextLines"].GetComponent <TextMesh>().text      = "Text lines: " + TextLines;
                buttons["TextLineLength"].GetComponent <TextMesh>().text = "Line length: " + TextLineLength + " characters";

                gameObject.GetComponent <TranslateToCamera>().EnableMovement = MoveWithMe;

                DepthObject.GetComponent <SpatialMappingRenderer>().enabled = DepthDebug;

                settings_set = true;
            }

            InputModule.CursorStateEnum cursorState = CursorObject.GetComponent <InputModule.AnimatedCursor>().CursorState;
            if (cursorState == InputModule.CursorStateEnum.Interact || cursorState == InputModule.CursorStateEnum.InteractHover || cursorState == InputModule.CursorStateEnum.Select)
            {
                InputModule.IPointingSource thisistoocomplex;
                if (InputModule.FocusManager.Instance.TryGetSinglePointer(out thisistoocomplex))
                {
                    GameObject focused = InputModule.FocusManager.Instance.GetFocusedObject(thisistoocomplex);

                    if (captions.Count > 1)
                    {
                        for (int i = captions.Count - 1; i >= 0; i--)
                        {
                            GameObject o = captions[i];
                            if (o.GetComponent <GlassEarTagalong>().frozen&& focused == o)
                            {
                                o.GetComponent <GlassEarTagalong>().lastHoverTime = Time.time;
                            }
                        }
                    }

                    foreach (KeyValuePair <string, GameObject> b in buttons)
                    {
                        if (focused == b.Value)
                        {
                            b.Value.GetComponent <HighightControl>().HoverTime = Time.time;
                        }
                    }
                }
            }
        }