public void AddGetRecordStatusEvent(System.Action <bool> actionCallback = null) { C_DebugHelper.LogErrorFormat("SpeechRecognizeSystemEvent AddGetRecordStatusEvent start "); _ActionCallback = actionCallback; if (_GetRecordStatusEvent != null) { _GetRecordStatusEvent.UnregisterEvent(); } _GetRecordStatusEvent = null; _GetRecordStatusEvent = new C_Event(); _GetRecordStatusEvent.RegisterEvent(C_EnumEventChannel.Global, "ResponseRecordStatus", (status) => { _GetRecordStatusEvent.UnregisterEvent(); if (status != null) { C_DebugHelper.LogErrorFormat("ResponseRecordStatus is :" + status); string answer = "1"; if (answer.Equals(status[0])) { if (_ActionCallback != null) { _ActionCallback(true); } } else { Tips.Create("开启语音权限后,才可以继续使用噢!"); if (_ActionCallback != null) { _ActionCallback(false); } } } }); }
/// <summary> /// 超时 判断 默认 正确 /// </summary> void StopWithStartOverTimeCheck() { //没网 弹窗tips 不走腾讯云语音识别 等待超时 if (Application.internetReachability == NetworkReachability.NotReachable) { DelayCallback = DOVirtual.DelayedCall(2f, () => { ClearEvent(); DoScoreCallBack("100"); C_DebugHelper.Log("本轮语音识别无网络,默认正确!"); }); Tips.Create("语音识别异常,请切换网络后重试"); return; } //等待结果返回,5秒之后如果没有返回结果,则自动返回 DelayCallback = DOVirtual.DelayedCall(_DelayTime, () => { ClearEvent(); DoScoreCallBack("100"); C_DebugHelper.Log("当轮语音识别没有拿到结果,默认正确!请确定网络状况是否良好!"); }); float time = Time.time; //float timeScale = Time.timeScale; //DelayCallback.OnUpdate(() => //{ // if (Time.timeScale != timeScale) // { // C_DebugHelper.Log("TimeScale:" + Time.timeScale); // timeScale = Time.timeScale; // } // C_DebugHelper.Log("花费时间:" + (Time.time - time)); //}); if (_GetTecentWordEvent != null) { _GetTecentWordEvent.UnregisterEvent(); } _GetTecentWordEvent = null; _GetTecentWordEvent = new C_Event(); _GetTecentWordEvent.RegisterEvent(C_EnumEventChannel.Global, "ResponseRecord", (word) => { //停掉超时计算 //if (DelayCallback != null) //{ // DelayCallback.Kill(); // DelayCallback = null; //} ClearEvent(); GetTecentReslut((word == null || word.Length <= 0) ? "" : word[0].ToString()); }); _IsRecording = false; }
protected void OnSceneChanged(Scene scene1, Scene scene2) { switch (_UnloadAndGameLoadState) { case UnloadAndGameLoadState.start: case UnloadAndGameLoadState.sceneload: { CloseUI(); } break; case UnloadAndGameLoadState.over: { if (mStop) { _SceneLoadEvent.UnregisterEvent(); _MainSceneLoadEvent.UnregisterEvent(); CutsceneSequencePlayer.StopCurrentCutscene(); //关闭ui CloseUI(); } } break; default: break; } }
protected override void onCloseUI() { _StartEvent.UnregisterEvent(); //停止刷新 _ProgressBar.fillAmount = 0f; release = true; close = true; }
/// <summary> /// 开始录音,腾讯云 /// </summary> /// <param name="answer"></param> /// <param name="scoreCallback"></param> public void StartRecognizeAudioTecent(string word, System.Action <string> scoreCallback, ResultType type = ResultType.PickScore, int langType = 1, int speechType = 1, float recordDur = 3f, bool reward = false) { _ResultCallback = scoreCallback; _ResultType = type; if (recordDur <= 0) { DoScoreCallBack("0"); C_DebugHelper.LogError("您设置的录音时间过短,请重新确认!"); return; } #if UNITY_EDITOR DelayStop = DOVirtual.DelayedCall(recordDur, () => { StopWithStartOverTimeCheck(); }); return; #endif if (_GetRecordStatusEvent != null) { _GetRecordStatusEvent.UnregisterEvent(); } _GetRecordStatusEvent = null; _GetRecordStatusEvent = new C_Event(); _GetRecordStatusEvent.RegisterEvent(C_EnumEventChannel.Global, "ResponseRecordStatus", (status) => { _GetRecordStatusEvent.UnregisterEvent(); if (status != null) { string answer = "1"; if (answer.Equals(status[0])) { _IsRecording = true; } else { Tips.Create("开启语音权限后,才可以继续使用噢!"); } } #if !UNITY_IOS StartRecordAction(recordDur); #endif }); _AnswerWord = word; #if UNITY_IOS StartRecordAction(recordDur); #endif }
public void ClearEvent() { DelayStop = null; if (DelayCallback != null) { DelayCallback.Kill(); DelayCallback = null; } if (_GetTecentWordEvent != null) { _GetTecentWordEvent.UnregisterEvent(); } _GetTecentWordEvent = null; if (_GetRecordStatusEvent != null) { _GetRecordStatusEvent.UnregisterEvent(); } _GetRecordStatusEvent = null; }