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; }
public void Start() { AudioWordDetection = GameObject.Find("WordDetection").GetComponent <WordDetection>(); AudioWordDetection.Mic = _Mic; // prepopulate words AudioWordDetection.Words.Add(new WordDetails() { Label = "Noise" }); //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
public override void OnInspectorGUI() { WordDetection item = target as WordDetection; item.Mic = (SpectrumMicrophone)EditorGUILayout.ObjectField("Spectrum Microphone:", item.Mic, typeof(SpectrumMicrophone), true); if (null != item.Mic) { int size = item.Mic.captureTime * item.Mic.sampleRate; GUILayout.BeginHorizontal(); GUILayout.Label("Threshold:"); item.Threshold = (int)GUILayout.HorizontalSlider(item.Threshold, 1, size); item.Threshold = EditorGUILayout.IntField(item.Threshold); item.Threshold = Mathf.Min(item.Threshold, size); item.Threshold = Mathf.Max(item.Threshold, 1); GUILayout.EndHorizontal(); item.UsePushToTalk = GUILayout.Toggle(item.UsePushToTalk, "Use Push To Talk"); } }
// 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; }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { // skip detection while recording if (m_recordingSample) { return; } if (null == args.Details || string.IsNullOrEmpty(args.Details.Label)) { m_command = "Noise"; } else { m_command = args.Details.Label; if (m_command != "Noise") { m_timerClearMic = DateTime.Now + TimeSpan.FromMilliseconds(200); if (m_command == WordDetectionInput.KEY_FORWARD) { WordDetectionInput.TimerDetection[m_command.ToUpper()] = DateTime.Now + TimeSpan.FromMilliseconds(1500f); } else { WordDetectionInput.TimerDetection[m_command.ToUpper()] = DateTime.Now + TimeSpan.FromMilliseconds(200f); } } } }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { if (null == args.Details) { return; } Debug.Log(args.Details.Label); if (args.Details.Label == GetWord(WORD_RESET).Label) { m_command = Commands.Reset; } else if (args.Details.Label == GetWord(WORD_GROW).Label) { m_command = Commands.Grow; } else if (args.Details.Label == GetWord(WORD_SHRINK).Label) { m_command = Commands.Shrink; } else if (args.Details.Label == GetWord(WORD_LEFT).Label) { m_command = Commands.Left; } else if (args.Details.Label == GetWord(WORD_RIGHT).Label) { m_command = Commands.Right; } else if (args.Details.Label == GetWord(WORD_UP).Label) { m_command = Commands.Up; } else if (args.Details.Label == GetWord(WORD_DOWN).Label) { m_command = Commands.Down; } }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { if (null == args.Details) { return; } if (args.Details.Label == "Reset") { m_command = Commands.Reset; } else if (args.Details.Label == "Grow") { m_command = Commands.Grow; } else if (args.Details.Label == "Shrink") { m_command = Commands.Shrink; } else if (args.Details.Label == "Left") { m_command = Commands.Left; } else if (args.Details.Label == "Right") { m_command = Commands.Right; } else if (args.Details.Label == "Up") { m_command = Commands.Up; } else if (args.Details.Label == "Down") { m_command = Commands.Down; } }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { if (null == args.Details || string.IsNullOrEmpty(args.Details.Label)) { m_command = Commands.Noise; return; } m_command = (Commands)Enum.Parse(typeof(Commands), args.Details.Label, false); PlayAnimation(GetStateName(m_command)); }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { if (string.IsNullOrEmpty(args.Details.Label)) { return; } Debug.Log(string.Format("Detected: {0}", args.Details.Label)); if (string.Compare(args.Details.Label, WORD_SITDOWN) == 0) { GameObject.FindGameObjectWithTag("Interact").GetComponent<Gesture>().SitDown(); } else if (string.Compare(args.Details.Label, WORD_FALLDOWN) == 0) { GameObject.FindGameObjectWithTag("Interact").GetComponent<Gesture>().FallDown(); }else if (string.Compare(args.Details.Label, WORD_STANDUP) == 0) { GameObject.FindGameObjectWithTag("Interact").GetComponent<Gesture>().StandUp(); }else if (string.Compare(args.Details.Label, WORD_RIGHTRAWUP) == 0) { GameObject.FindGameObjectWithTag("Interact").GetComponent<Gesture>().RightRawUp(); }else if (string.Compare(args.Details.Label, WORD_LEFTRAWUP) == 0) { GameObject.FindGameObjectWithTag("Interact").GetComponent<Gesture>().LeftRawUp(); } }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { // skip detection while recording if (m_recordingSample) { return; } if (null == args.Details || string.IsNullOrEmpty(args.Details.Label)) { m_command = "Noise"; } else { m_command = args.Details.Label; if (m_command != "Noise") { m_timerClearMic = DateTime.Now + TimeSpan.FromMilliseconds(200); m_detected[m_command] = DateTime.Now + TimeSpan.FromSeconds(1); } } }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { // skip detection while recording if (m_recordingSample) { return; } if (null == args.Details || string.IsNullOrEmpty(args.Details.Label)) { m_command = Commands.Noise; return; } if (m_modeTimer > DateTime.Now) { m_command = Commands.Noise; return; } //Debug.Log(args.Details.Label); switch (m_mode) { case Modes.Set1: if (args.Details.Label == Commands.Go.ToString()) { AudioWordDetection.Words = m_set2; m_mode = Modes.Set2; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(1000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } break; case Modes.Set2: if (args.Details.Label == Commands.Back.ToString()) { AudioWordDetection.Words = m_set1; m_mode = Modes.Set1; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(1000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } else if (args.Details.Label == Commands.Action.ToString()) { AudioWordDetection.Words = m_set3; m_mode = Modes.Set3; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(2000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } else if (args.Details.Label == Commands.Misc.ToString()) { AudioWordDetection.Words = m_set4; m_mode = Modes.Set4; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(2000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } break; case Modes.Set3: case Modes.Set4: if (args.Details.Label == Commands.Back.ToString()) { AudioWordDetection.Words = m_set2; m_mode = Modes.Set2; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(1000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } else if (args.Details.Label != Commands.Noise.ToString()) { AudioWordDetection.Words = m_set1; m_mode = Modes.Set1; m_modeTimer = DateTime.Now + TimeSpan.FromMilliseconds(2000); Mic.ClearData(); m_wordsChanged = true; m_command = Commands.Noise; } break; } m_command = (Commands)Enum.Parse(typeof(Commands), args.Details.Label, false); PlayAnimation(GetStateName(m_command)); }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { if (string.IsNullOrEmpty(args.Details.Label)) { return; } Debug.Log(string.Format("Detected: {0}", args.Details.Label)); }
/// <summary> /// Handle word detected event /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void WordDetectedHandler(object sender, WordDetection.WordEventArgs args) { // skip detection while recording if (m_recordingSample) { return; } if (null == args.Details || string.IsNullOrEmpty(args.Details.Label)) { m_command = Commands.Noise; return; } m_command = (Commands)Enum.Parse(typeof(Commands), args.Details.Label, false); }