Exemple #1
0
    void OnLevelWasLoaded(int level)
    {
        isActive = true;

        //untuk voice command
        MicG  = GameObject.Find("SpectrumMicrophone");
        WordG = GameObject.Find("WordDetection");
        Mic   = MicG.GetComponents <SpectrumMicrophone>()[0];
        AudioWordDetection = WordG.GetComponents <WordDetection>()[0];

        if (null == AudioWordDetection ||
            null == Mic)
        {
            Debug.LogError("Missing meta references");
            return;
        }

        // prepopulate words
        AudioWordDetection.Words.Add(new WordDetails()
        {
            Label = "Noise"
        });
        AudioWordDetection.Words.Add(new WordDetails()
        {
            Label = "Ultimate"
        });

        //subscribe detection event
        AudioWordDetection.WordDetectedEvent += WordDetectedHandler;
    }
 /// <summary>
 /// Initialize the example
 /// </summary>
 public override void OnInit()
 {
     //AudioWordDetection = gameObject.AddComponent<WordDetection> ();
     _WordServe = WordService.Instance;
     _Mic       = _WordServe.Mic;
     //AudioWordDetection.Mic = _Mic;
     if (
         null == _Mic)
     {
         Debug.LogError("Missing meta references");
         return;
     }
 }
    public override void OnInspectorGUI()
    {
        SpectrumMicrophone item = target as SpectrumMicrophone;

        int captureTime = item.CaptureTime;
        int sampleRate  = item.SampleRate;

        GUILayout.BeginHorizontal();
        GUILayout.Label("Capture Time:");
        item.CaptureTime = (int)GUILayout.HorizontalSlider(item.CaptureTime, 1, 16);
        item.CaptureTime = EditorGUILayout.IntField(item.CaptureTime);
        int log = (int)Mathf.Log(item.CaptureTime, 2);

        item.CaptureTime = (int)Mathf.Pow(2, log);
        item.CaptureTime = Mathf.Min(item.CaptureTime, 16);
        item.CaptureTime = Mathf.Max(item.CaptureTime, 1);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Sample Rate:");
        item.SampleRate = (int)GUILayout.HorizontalSlider(item.SampleRate, 1024, 65536);
        item.SampleRate = EditorGUILayout.IntField(item.SampleRate);
        log             = (int)Mathf.Log(item.SampleRate, 2);
        item.SampleRate = (int)Mathf.Pow(2, log);
        item.SampleRate = Mathf.Min(item.SampleRate, 65536);
        item.SampleRate = Mathf.Max(item.SampleRate, 1024);
        GUILayout.EndHorizontal();

        if (captureTime != item.CaptureTime ||
            sampleRate != item.SampleRate)
        {
            if (EditorApplication.isPlaying)
            {
                item.CleanUp();
                item.InitData();
            }
        }
    }
Exemple #4
0
    // Use this for initialization
    void Start()
    {
        MicG  = GameObject.Find("SpectrumMicrophone");
        WordG = GameObject.Find("WordDetection");
        Mic   = MicG.GetComponents <SpectrumMicrophone>()[0];
        AudioWordDetection = WordG.GetComponents <WordDetection>()[0];

        //get the screen's width
        sWidth  = Screen.width;
        sHeight = Screen.height;
        //calculate the rescale ratio
        guiRatioX = sWidth / 1280;
        guiRatioY = sHeight / 720;
        //create a rescale Vector3 with the above ratio
        GUIsF = new Vector3(guiRatioX, guiRatioY, 1);

        if (null == AudioWordDetection ||
            null == Mic)
        {
            //Debug.LogError("Missing meta references");
            return;
        }

        // prepopulate words
        AudioWordDetection.Words.Add(new WordDetails()
        {
            Label = "Noise"
        });
        AudioWordDetection.Words.Add(new WordDetails()
        {
            Label = "Ultimate"
        });

        //subscribe detection event
        AudioWordDetection.WordDetectedEvent += WordDetectedHandler;
    }
Exemple #5
0
    public override void OnInit()
    {
        base.OnInit();

        Mic             = gameObject.AddComponent <SpectrumMicrophone> ();
        Mic.CaptureTime = 1;
        Mic.SampleRate  = 1024;

        if (UsePlotter)
        {
            UIManager.UIData data = UIManager.Instance.Open(UIID.Plotter);
            if (data != null)
            {
                GameObject plane  = data.UIObject;
                Transform  plane1 = plane.transform.FindChild("planeLeft");
                RendererSpectrumLeft = plane1.GetComponent <Image> ();
                Transform plane2 = plane.transform.FindChild("planeRight");
                RendererSpectrumRight = plane2.GetComponent <Image> ();
                Transform plane3 = plane.transform.FindChild("planeWave");
                RendererWave = plane3.GetComponent <Image> ();
            }
//			planes = new GameObject ();
//			planes.name = "planes";
//			GameObject planeLeft = GameObject.CreatePrimitive (PrimitiveType.Plane);
//			planeLeft.GetComponent<Collider> ().enabled = false;
//			planeLeft.transform.position = new Vector3 (5.1f, 0, 10);
//			planeLeft.transform.parent = planes.transform;
//			planeLeft.layer = LayerMask.NameToLayer ("UI");
//			RendererSpectrumLeft = planeLeft.GetComponent<MeshRenderer> ();
//
//			GameObject planeRight = GameObject.CreatePrimitive (PrimitiveType.Plane);
//			planeRight.GetComponent<Collider> ().enabled = false;
//			planeRight.transform.position = new Vector3 (-5.1f, 0, 10);
//			planeRight.transform.parent = planes.transform;
//			planeRight.layer = LayerMask.NameToLayer ("UI");
//			RendererSpectrumRight = planeRight.GetComponent<MeshRenderer> ();
//
//			GameObject planeWave = GameObject.CreatePrimitive (PrimitiveType.Plane);
//			planeWave.GetComponent<Collider> ().enabled = false;
//			planeWave.transform.position = new Vector3 (0, 0, -1);
//			planeWave.transform.localScale = new Vector3 (2, 1, 1);
//			planeWave.transform.parent = planes.transform;
//			planeWave.layer = LayerMask.NameToLayer ("UI");
//			RendererWave = planeWave.GetComponent<MeshRenderer> ();
//
//			//planes.AddComponent<Billboard> ();
//			planes.transform.localPosition
//			= new Vector3 (1f
//				, 3.3f
//				, 1f);
//			planes.transform.localRotation = Quaternion.Euler (100.30659f, 186.228242f, 185.8563f);
//			planes.transform.localScale = new Vector3(0.05f,0.05f,0.05f);
//			planes.transform.parent = Camera.main.transform;
//			planes.layer = LayerMask.NameToLayer ("UI");
        }

        if (MaterialSpectrumLeft &&
            RendererSpectrumLeft)
        {
            RendererSpectrumLeft.material = (Material)UnityEngine.Object.Instantiate(MaterialSpectrumLeft);
        }

        if (MaterialSpectrumRight &&
            RendererSpectrumRight)
        {
            RendererSpectrumRight.material = (Material)UnityEngine.Object.Instantiate(MaterialSpectrumRight);
        }

        if (MaterialWave &&
            RendererWave)
        {
            RendererWave.material = (Material)UnityEngine.Object.Instantiate(MaterialWave);
        }

        if (null == m_textureSpectrumLeft &&
            RendererSpectrumLeft)
        {
            m_textureSpectrumLeft                     = new Texture2D(TextureSize, TextureSize, TextureFormat.ARGB32, false);
            m_textureSpectrumLeft.wrapMode            = TextureWrapMode.Clamp;
            m_textureSpectrumLeft.filterMode          = FilterMode.Point;
            m_textureSpectrumLeft.anisoLevel          = 0;
            RendererSpectrumLeft.material.mainTexture = m_textureSpectrumLeft;
            m_colorsSpectrumLeft = m_textureSpectrumLeft.GetPixels32();
        }

        if (null == m_textureSpectrumRight &&
            RendererSpectrumRight)
        {
            m_textureSpectrumRight                     = new Texture2D(TextureSize, TextureSize, TextureFormat.ARGB32, false);
            m_textureSpectrumRight.wrapMode            = TextureWrapMode.Clamp;
            m_textureSpectrumRight.filterMode          = FilterMode.Point;
            m_textureSpectrumRight.anisoLevel          = 0;
            RendererSpectrumRight.material.mainTexture = m_textureSpectrumRight;
            m_colorsSpectrumRight = m_textureSpectrumRight.GetPixels32();
        }

        if (null == m_textureWave &&
            RendererWave)
        {
            m_textureWave                     = new Texture2D(TextureSize, TextureSize, TextureFormat.ARGB32, false);
            m_textureWave.wrapMode            = TextureWrapMode.Repeat;
            m_textureWave.filterMode          = FilterMode.Point;
            m_textureWave.anisoLevel          = 0;
            RendererWave.material.mainTexture = m_textureWave;
            m_colorsWave = m_textureWave.GetPixels32();
        }

        m_plotter.TextureSize = TextureSize;
    }