void Update() { // skip detection while recording if (m_recordingSample) { return; } foreach (string command in m_blendShapes) { int index = m_blendShapes.IndexOf(command); float val = Head.GetBlendShapeWeight(index); if (command == m_command) { val = Mathf.Min(100f, val + Time.deltaTime * 1000f); Head.SetBlendShapeWeight(index, val); } else { val = Mathf.Max(0f, val - Time.deltaTime * 1000f); Head.SetBlendShapeWeight(index, val); } } if (m_timerClearMic != DateTime.MinValue) { if (m_timerClearMic < DateTime.Now) { m_timerClearMic = DateTime.MinValue; Mic.ClearData(); } } }
void Update() { // skip detection while recording if (m_recordingSample) { return; } bool found = false; foreach (MeshRenderer expression in m_expressions) { String command = expression.name; if (command == m_command) { expression.enabled = true; found = true; } else { expression.enabled = false; } } m_Noise.enabled = !found; if (m_timerClearMic != DateTime.MinValue) { if (m_timerClearMic < DateTime.Now) { m_timerClearMic = DateTime.MinValue; Mic.ClearData(); } } }
void Update() { // skip detection while recording if (m_recordingSample) { return; } if (null == VideoStage) { return; } if (m_map.ContainsKey(m_command)) { if (m_timerGoat < DateTime.Now) { if (m_map[m_command].m_material) { VideoStage.material = m_map[m_command].m_material; if (VideoStage.material.mainTexture) { MovieTexture movieTexture = VideoStage.material.mainTexture as MovieTexture; if (movieTexture) { movieTexture.Stop(); movieTexture.Play(); if (m_map[m_command].m_audioClip) { GoatAudioSource.mute = false; GoatAudioSource.loop = false; m_timerGoat = DateTime.Now + TimeSpan.FromSeconds(m_map[m_command].m_audioClip.length); GoatAudioSource.PlayOneShot(m_map[m_command].m_audioClip); } } } } } } if (m_timerClearMic != DateTime.MinValue) { if (m_timerClearMic < DateTime.Now) { m_timerClearMic = DateTime.MinValue; Mic.ClearData(); } } }
void Update() { // skip detection while recording if (m_recordingSample) { return; } if (m_timerClearMic != DateTime.MinValue) { if (m_timerClearMic < DateTime.Now) { m_timerClearMic = DateTime.MinValue; Mic.ClearData(); } } }
void Update() { // skip detection while recording if (m_recordingSample) { return; } foreach (string command in m_blendShapes) { int index = m_blendShapes.IndexOf(command); float val = Head.GetBlendShapeWeight(index); if (m_detected.ContainsKey(command) && m_detected[command] > DateTime.Now) { float elapsed = (float)(m_detected[command] - DateTime.Now).TotalSeconds; // 1 to 0 // -2t - 1 // -1 to 1 // cos(PI/2*(2t-1)) // 0 to 1 to 0 //val = Mathf.Min(100f, 100 * Mathf.Cos(Mathf.PI*0.5f*2*elapsed-1)); val = Mathf.Min(100f, 100 * Mathf.Cos(Mathf.PI * elapsed - 1)); Head.SetBlendShapeWeight(index, val); } else { val = Mathf.Max(0f, val - Time.deltaTime * 1000f); Head.SetBlendShapeWeight(index, val); } } if (m_timerClearMic != DateTime.MinValue) { if (m_timerClearMic < DateTime.Now) { m_timerClearMic = DateTime.MinValue; Mic.ClearData(); } } }
/// <summary> /// GUI event /// </summary> protected override void OnGUI() { if (null == AudioWordDetection || null == Mic || string.IsNullOrEmpty(Mic.DeviceName)) { return; } Color backgroundColor = GUI.backgroundColor; for (int wordIndex = 0; wordIndex < AudioWordDetection.Words.Count; ++wordIndex) { if (m_wordsChanged) { m_wordsChanged = false; GUIUtility.ExitGUI(); } if (AudioWordDetection.ClosestIndex == wordIndex) { GUI.backgroundColor = Color.red; } else { GUI.backgroundColor = backgroundColor; } WordDetails noise = GetWord(WORD_NOISE); if (null == noise) { continue; } if (wordIndex > 0) { GUI.enabled = null != noise.SpectrumReal; } GUILayout.BeginHorizontal(GUILayout.MinWidth(600)); WordDetails details = AudioWordDetection.Words[wordIndex]; if (GUILayout.Button("Play", GUILayout.Height(45))) { if (null != details.Audio) { if (NormalizeWave) { GetComponent <AudioSource>().PlayOneShot(details.Audio, 0.1f); } else { GetComponent <AudioSource>().PlayOneShot(details.Audio); } } // show profile RefExample.OverrideSpectrumImag = true; RefExample.SpectrumImag = details.SpectrumReal; } if (wordIndex == 0) { GUILayout.Label(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } else { details.Label = GUILayout.TextField(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } GUILayout.Button(string.Format("{0}", (null == details.SpectrumReal) ? "not set" : "set"), GUILayout.Height(45)); Event e = Event.current; if (null != e) { Rect rect = GUILayoutUtility.GetLastRect(); bool overButton = rect.Contains(e.mousePosition); if (m_buttonIndex == -1 && m_timerStart == DateTime.MinValue && Input.GetMouseButton(0) && overButton) { //Debug.Log("Initial button down"); m_buttonIndex = wordIndex; m_startPosition = Mic.GetPosition(); m_timerStart = DateTime.Now + TimeSpan.FromSeconds(Mic.CaptureTime); m_recordingSample = true; } if (m_buttonIndex == wordIndex) { bool buttonUp = Input.GetMouseButtonUp(0); if (m_timerStart > DateTime.Now && !buttonUp) { //Debug.Log("Button still pressed"); m_recordingSample = true; } else if (m_timerStart != DateTime.MinValue && m_timerStart < DateTime.Now) { //Debug.Log("Button timed out"); SetupWordProfile(false); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; m_recordingSample = false; Mic.ClearData(); } else if (m_timerStart != DateTime.MinValue && buttonUp && m_buttonIndex != -1) { //Debug.Log("Button is no longer pressed"); SetupWordProfile(true); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; m_recordingSample = false; Mic.ClearData(); SaveProfile(details); } } } //GUILayout.Label(details.Score.ToString()); //GUILayout.Label(string.Format("{0}", details.GetMinScore(DateTime.Now - TimeSpan.FromSeconds(1)))); GUILayout.EndHorizontal(); if (wordIndex > 0) { GUI.enabled = null != noise.SpectrumReal; } GUILayout.Space(10); } GUI.backgroundColor = backgroundColor; GUI.enabled = true; }
/// <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)); }