public void StopAndGetResult() { string result = ""; Microphone.End(null); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { result = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; lastContent = result; if (Eve解析完成 != null && result != "未识别到声音") { Eve解析完成(result); } else if (Eve未检测到声音 != null && result == "未识别到声音") { Eve未检测到声音(); } //Debug.Log("结束录音:" + result); })); if (Eve结束录音 != null) { Eve结束录音(); } }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "转换中..."; Microphone.End(null); //清空 var data = Asr.ConvertAudioClipToPCM16(_clipRecord); //转换成byte数据 //将byte传入 然后转换 StartCoroutine(_asr.Recognize(data, s => { //转换回掉函数 文本=转换结果不为空且结果长度大于0 否则为“未识别声音” if (s.result == null) { DescriptionText.text = "未识别到声音"; StartButton.gameObject.SetActive(true); } else { RecognitionResult(s.result[0]); } })); }
private void StopRecording() { //此时判断是否处于说话状态,如果是说话状态则将按钮复位,并上传说话内容 if (StartSpeech) { //上传内容 Log.Debug("麦克风停止录音"); Microphone.End(null); //转换格式 var data = Asr.ConvertAudioClipToPCM16(clipRecord); asr.Recognize(data, s => { Log.Debug("进来了"); if (s.result == null && s.result.Length < 0) { Log.Debug("结果为空,表示麦克风未识别到声音"); //提示有问题,复位 entry2.callback.AddListener(N); StartSpeech = false; } else { //有结果,发送给机器人进行语音回复 tts.Synthesis(s.result[0], r => { if (r.Success) { //正常播放 Log.Debug("合成成功,正在播放,声音有几秒:" + audioSource.clip.length); audioSource.clip = r.clip; audioSource.Play(); //复位 entry2.callback.AddListener(N); StartSpeech = false; } else { //这是出问题了 Debug.Log(s.err_msg); //提示有问题,复位 entry2.callback.AddListener(N); StartSpeech = false; } }); } }); } }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "Recognizing..."; Microphone.End(null); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { message = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; char[] messageChar = message.ToCharArray(); int temporary = 1; int chamber = ToDigit(messageChar[(message.IndexOf("病房") - temporary)]); for (temporary = 1; temporary < message.IndexOf("病房");) { //如病房前面还有字 第六个病房 etc. 接着往前找 if (chamber == 0) { chamber = ToDigit(message[(message.IndexOf("病房") - (++temporary))]); } else if (chamber != 0) {//找到了 break; } } message2 = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; //0none,1开灯2关灯3消毒4通风 int operate = 0; string[] operates = { "", "开灯", "关灯", "消毒", "通风" }; for (int i = 1; i <= 4;) { int t = message2.IndexOf(operates[i]); if (t == (-1)) { i++; } else { operate = i; break; } }//用indexof寻找关键字,没找到返回-1 找到了赋给operate // chamber 1,2,3,4,5,6,7,8 // operate 1,2,3,4 DescriptionText.text = chamber.ToString() + "," + operate; StartButton.gameObject.SetActive(true); })); }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "Recognizing..."; Microphone.End(null); Debug.Log("end record"); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { DescriptionText.text = s.result[0]; StartButton.gameObject.SetActive(true); })); }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "Recognizing..."; Microphone.End(null); Debug.Log("[WitBaiduAip demo]end record"); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); ReplayButton.gameObject.SetActive(true); StartCoroutine(_asr.Recognize(data, s => { DescriptionText.text = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; StartButton.gameObject.SetActive(true); })); }
IEnumerator Timer() { while (true) { yield return(new WaitForSeconds(inteval)); Microphone.End(null); // print(_clipRecord.length); updateClips(); AudioClip currentClip = AudioClipHelper.Combine((AudioClip[])_audioClips.ToArray(typeof(AudioClip))); // AudioClip currentClip = AudioClipHelper.Combine(_audioClips); // AudioClip currentClip = (AudioClip) _audioClips[0]; var data = Asr.ConvertAudioClipToPCM16(currentClip); StartCoroutine(_asr.Recognize(data, s => { String text = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; Debug.Log(DateTime.Now + ":" + text); })); } }
private void OnClickStopButton() { dogs = pjt.GetComponent <AsrForPjt>().dog; Debug.Log("sssss" + "," + dogs); StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "Recognizing..."; Microphone.End(null); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { message = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; char[] messageChar = message.ToCharArray(); //Convenient access by index if ((message.IndexOf("病房")) == -1) { Debug.Log("repeat"); } else //Start Algorithm { int temporary = 1; int chamber = ToDigit(messageChar[(message.IndexOf("病房") - temporary)]); for (temporary = 1; temporary < message.IndexOf("病房");) { //if there's another character before"病房" like "第六个病房" etc. still Still searching forward if (chamber == 0) { chamber = ToDigit(message[(message.IndexOf("病房") - (++temporary))]); } else if (chamber != 0) {// we got it! break; } } message2 = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; //0none,1开灯2关灯3消毒4开门 int operate = 0; string[] operates = { "", "开灯", "关灯", "消毒", "开门" }; for (int i = 1; i <= operates.Length;) { int t = message2.IndexOf(operates[i]); if (t == (-1)) { i++; } else { operate = i; break; } }//用indexof寻找关键字,没找到返回-1 找到了赋给operate // chamber 1,2,3,4,5,6,7,8 // operate 1,2,3,4 if (chamber == 1 && operate == 1) { light1.SetActive(true); } else if (chamber == 1 && operate == 2) { light1.SetActive(false); } else if (chamber == 1 && operate == 3) { Debug.Log(dogs); if (dogs == 1) { ap.Play(); } else { smoke1.Play(); cock1.Stop(); } } else if (chamber == 1 && operate == 4) { door1.transform.position = new Vector3(door1.transform.position.x, door1.transform.position.y, door1.transform.position.z + 2); } if (chamber == 2 && operate == 1) { light2.SetActive(true); } else if (chamber == 2 && operate == 2) { light2.SetActive(false); } else if (chamber == 2 && operate == 3) { Debug.Log(dogs); if (dogs == 2) { ap.Play(); } else { smoke2.Play(); cock2.Stop(); } } else if (chamber == 2 && operate == 4) { door2.transform.position = new Vector3(door2.transform.position.x, door2.transform.position.y, door2.transform.position.z + 2); } if (chamber == 3 && operate == 1) { light3.SetActive(true); } else if (chamber == 3 && operate == 2) { light3.SetActive(false); } else if (chamber == 3 && operate == 3) { Debug.Log(dogs); if (dogs == 3) { ap.Play(); } else { smoke3.Play(); cock3.Stop(); } } else if (chamber == 3 && operate == 4) { door3.transform.position = new Vector3(door3.transform.position.x, door3.transform.position.y, door3.transform.position.z + 2); } if (chamber == 4 && operate == 1) { light4.SetActive(true); } else if (chamber == 4 && operate == 2) { light4.SetActive(false); } else if (chamber == 4 && operate == 3) { Debug.Log(dogs); if (dogs == 4) { ap.Play(); } else { smoke4.Play(); cock4.Stop(); } } else if (chamber == 4 && operate == 4) { door4.transform.position = new Vector3(door4.transform.position.x, door4.transform.position.y, door4.transform.position.z + 2); } if (chamber == 5 && operate == 1) { light5.SetActive(true); } else if (chamber == 5 && operate == 2) { light5.SetActive(false); } else if (chamber == 5 && operate == 3) { Debug.Log(dogs); if (dogs == 5) { ap.Play(); } else { smoke5.Play(); cock5.Stop(); } } else if (chamber == 5 && operate == 4) { door5.transform.position = new Vector3(door5.transform.position.x, door5.transform.position.y, door5.transform.position.z + 2); } if (chamber == 6 && operate == 1) { light6.SetActive(true); } else if (chamber == 6 && operate == 2) { light6.SetActive(false); } else if (chamber == 6 && operate == 3) { Debug.Log(dogs); if (dogs == 6) { ap.Play(); } else { smoke6.Play(); cock6.Stop(); } } else if (chamber == 6 && operate == 4) { door6.transform.position = new Vector3(door6.transform.position.x, door6.transform.position.y, door6.transform.position.z + 2); } if (chamber == 7 && operate == 1) { light7.SetActive(true); } else if (chamber == 7 && operate == 2) { light7.SetActive(false); } else if (chamber == 7 && operate == 3) { Debug.Log(dogs); if (dogs == 7) { ap.Play(); } else { smoke7.Play(); cock7.Stop(); } } else if (chamber == 7 && operate == 4) { door7.transform.position = new Vector3(door7.transform.position.x, door7.transform.position.y, door7.transform.position.z + 2); } if (chamber == 8 && operate == 1) { light8.SetActive(true); } else if (chamber == 8 && operate == 2) { light8.SetActive(false); } else if (chamber == 8 && operate == 3) { Debug.Log(dogs); if (dogs == 8) { ap.Play(); } else { smoke8.Play(); cock8.Stop(); } } else if (chamber == 8 && operate == 4) { door8.transform.position = new Vector3(door8.transform.position.x, door8.transform.position.y, door1.transform.position.z + 2); } if (chamber == 9 && operate == 1) { lightmain.SetActive(true); } else if (chamber == 9 && operate == 2) { lightmain.SetActive(false); } else if (chamber == 9 && operate == 3) { ap.Play(); } DescriptionText.text = chamber.ToString() + "," + operate; } DescriptionText.text = ""; StartButton.gameObject.SetActive(true); })); }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "Recognizing..."; Microphone.End(null); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { message = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; char[] messageChar = message.ToCharArray(); int temporary = 1; if ((message.IndexOf("病房") == -1)) { Debug.Log("repeat"); } else { int chamber = ToDigit(messageChar[(message.IndexOf("病房") - temporary)]); for (temporary = 1; temporary < message.IndexOf("病房");) { //如病房前面还有字 第六个病房 etc. 接着往前找 if (chamber == 0) { chamber = ToDigit(message[(message.IndexOf("病房") - (++temporary))]); } else if (chamber != 0) {//找到了 break; } else { Debug.Log("repeat"); DescriptionText.text = "repeat"; chamber = 0; temporary = 1; break; } } message2 = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; //0none,1开灯2关灯3消毒4通风 int operate = 0; string[] operates = { "", "开灯", "关灯", "消毒", "喷淋" }; for (int i = 1; i <= 4;) { int t = message2.IndexOf(operates[i]); if (t == (-1)) { i++; } else { operate = i; break; } }//用indexof寻找关键字,没找到返回-1 找到了赋给operate // chamber 1,2,3,4,5,6,7,8 // operate 1,2,3,4 if (chamber == 1 && operate == 1) { light1.SetActive(true); } else if (chamber == 1 && operate == 2) { light1.SetActive(false); } else if (chamber == 1 && operate == 3) { Debug.Log(dog); if (dog == 1) { ap.Play(); } else { smoke1.Play(); cock1.Stop(); } } if (chamber == 2 && operate == 1) { light2.SetActive(true); } else if (chamber == 2 && operate == 2) { light2.SetActive(false); } else if (chamber == 2 && operate == 3) { Debug.Log(dog); if (dog == 2) { ap.Play(); } else { smoke2.Play(); cock2.Stop(); } } if (chamber == 3 && operate == 1) { light3.SetActive(true); } else if (chamber == 3 && operate == 2) { light3.SetActive(false); } else if (chamber == 3 && operate == 3) { Debug.Log(dog); if (dog == 3) { ap.Play(); } else { smoke3.Play(); cock3.Stop(); } } if (chamber == 4 && operate == 1) { light4.SetActive(true); } else if (chamber == 4 && operate == 2) { light4.SetActive(false); } else if (chamber == 4 && operate == 3) { Debug.Log(dog); if (dog == 4) { ap.Play(); } else { smoke4.Play(); cock4.Stop(); } } if (chamber == 5 && operate == 1) { light5.SetActive(true); } else if (chamber == 5 && operate == 2) { light5.SetActive(false); } else if (chamber == 5 && operate == 3) { Debug.Log(dog); if (dog == 5) { ap.Play(); } else { smoke5.Play(); cock5.Stop(); } } if (chamber == 6 && operate == 1) { light6.SetActive(true); } else if (chamber == 6 && operate == 2) { light6.SetActive(false); } else if (chamber == 6 && operate == 3) { Debug.Log(dog); if (dog == 6) { ap.Play(); } else { smoke6.Play(); cock6.Stop(); } } if (chamber == 7 && operate == 1) { light7.SetActive(true); } else if (chamber == 7 && operate == 2) { light7.SetActive(false); } else if (chamber == 7 && operate == 3) { Debug.Log(dog); if (dog == 7) { ap.Play(); } else { smoke7.Play(); cock7.Stop(); } } if (chamber == 8 && operate == 1) { light8.SetActive(true); } else if (chamber == 8 && operate == 2) { light8.SetActive(false); } else if (chamber == 8 && operate == 3) { Debug.Log(dog); if (dog == 8) { ap.Play(); } else { smoke8.Play(); cock8.Stop(); } } if (chamber == 9 && operate == 1) { lightmain.SetActive(true); } else if (chamber == 9 && operate == 2) { lightmain.SetActive(false); } else if (chamber == 9 && operate == 3) { ap.Play(); } DescriptionText.text = chamber.ToString() + "," + operate; } DescriptionText.text = ""; StartButton.gameObject.SetActive(true); })); }