public static void startLogin() { Debug.Log("Start listen vocal print"); StartRecording(); SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().logprocess); logining = true; }
public static GameObject ShowMessage(string msg) { SoundsControl.playAudio(MainCamera.GetComponent <PrefebCollector>().msg); GameObject obj = Instantiate(Msg); obj.name = "msg_clone"; obj.transform.position = new Vector3(facePosition.x, facePosition.y - 0.2f, facePosition.z); obj.transform.rotation = faceRotation; obj.transform.Find("Text").GetComponent <Text>().text = msg; obj.SetActive(true); Menu.SetActive(false); return(obj); }
private bool log(string[] entities) { try { foreach (string now in entities) { if (now.Contains("out") || now.Contains("unsign")) { ControlCenter.SetString("id", "-1"); Login.logining = false; SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().msg); return(true); } else if (now.Contains("in") || now.Contains("sign") || now.Contains("log")) { Login.startLogin(); return(true); } } } catch { return(false); } return(false); }
public static void startListen() { SoundsControl.playAudio(MainCamera.GetComponent <PrefebCollector>().vocalstart); VocalListener.StartRecording(); }
// Update is called once per frame void Update() { if (Login.logining) { return; } if (resultAu != null && resultAu != "") { Debug.Log(resultAu);//输出最终结果 if (resultAu.Contains("Error")) { ControlCenter.ShowMessage(Language.lang.error); } string operate = resultAu; resultAu = null; ControlCenter.MainCamera.GetComponent <LanguageUnderstand>().go(operate); } if (backgrountVolume == 0 && !Microphone.IsRecording(null)) { Start(); } else if (backgrountVolume == 0 && Microphone.IsRecording(null)) { float length2 = Microphone.GetPosition(null) / samplingRate; if (length2 >= 2) { AudioClip outClip = new AudioClip(); int outlength = 0; float[] source2 = new float[Microphone.GetPosition(null) * clip.channels]; EndRecording(out outlength, out outClip); clip.GetData(source2, 0); Array.Copy(source2, source2.Length - 16000, source2, 0, 16000); foreach (float now in source2) { backgrountVolume += Mathf.Abs(now); } backgrountVolume /= source2.Length; maxRecordTime = 10; } return; } if (!Microphone.IsRecording(null)) { return; } float length = Microphone.GetPosition(null) / samplingRate; if (length >= 2) { float[] sourceI = new float[Microphone.GetPosition(null) * clip.channels]; float[] source = new float[24000]; clip.GetData(sourceI, 0); Array.Copy(sourceI, sourceI.Length - 24000, source, 0, 24000); average = 0f; foreach (float now in source) { average += Mathf.Abs(now); } average /= source.Length; if ((Microphone.IsRecording(null) && !(average > backgrountVolume * 1.2f) && length > 1.5f) || length > 9.9f) { AudioClip outClip = new AudioClip(); int outlength = 0; EndRecording(out outlength, out outClip); if (length > 2.1f) { Debug.Log("Start get text"); LanguageUnderstand.ListenIcon = ListenIcon; SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().vocalend); StartCoroutine(GetTextFromAudio(getWAV(outClip))); resultAu = ""; //Debug.Log(GetTextFromAudio(getWAV(outClip))); } else { ListenIcon.SetActive(false); } } } }
// Update is called once per frame void Update() { if (logining && Microphone.IsRecording(null)) { float length = Microphone.GetPosition(null) / samplingRate; if (length >= 2) { double average = 0.0; float[] sourceI = new float[Microphone.GetPosition(null) * clip.channels]; float[] source = new float[24000]; clip.GetData(sourceI, 0); Array.Copy(sourceI, sourceI.Length - 24000, source, 0, 24000); average = 0f; foreach (float now in source) { average += Mathf.Abs(now); } average /= source.Length; if ((Microphone.IsRecording(null) && !(average > VocalListener.backgrountVolume * 1.2f) && length > 1.5f) || length > 9.9f) { AudioClip outClip = new AudioClip(); int outlength = 0; EndRecording(out outlength, out outClip); if (length > 2.1f) { Debug.Log("Start post to login"); //ListenIcon.SetActive(false); SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().vocalend); byte[] data = getWAV(outClip); StartCoroutine(login(data)); } else { ListenIcon.SetActive(false); SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().vocalend); ControlCenter.ShowMessage(Language.lang.loginfail); } } } } if (!string.IsNullOrEmpty(result)) { Debug.Log(result); try { if (int.Parse(result) > 0) { ControlCenter.SetString("id", result); result = null; SoundsControl.playAudio(ControlCenter.MainCamera.GetComponent <PrefebCollector>().logfinish); } else { ControlCenter.ShowMessage(Language.lang.loginfail); result = null; } } catch { ControlCenter.ShowMessage(Language.lang.loginfail); result = null; } } }