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); } } } }); }
public string StopRecord() { /* if (!Microphone.IsRecording(null)) * { * return null; * }*/ C_DebugHelper.LogErrorFormat("MicphoneSinglton StopRecord line56 ..."); Microphone.End(null); audio.Stop(); //保存语音文件 // WavUtility.FromAudioClip(audio.clip, out _CurrentAudioFilePath); return(_CurrentAudioFilePath); }
public void StartRecord() { C_DebugHelper.LogErrorFormat("MicphoneSinglton StartRecord ..."); #if UNITY_EDITOR #else audio.Stop(); audio.loop = false; audio.mute = true; Microphone.End(null); audio.clip = Microphone.Start(null, false, 5, int.Parse(sFrequency)); C_DebugHelper.LogErrorFormat("MicphoneSinglton StartRecord ... line46 "); #endif }
//private IEnumerator GetRecordVolume(float pitch,System.Action<bool,float> callback, System.Action playOver =null) //{ // StartCoroutine(EndRecordWithoutSaveData(pitch, callback, playOver)); // WaitForEndOfFrame endOfFrame = new WaitForEndOfFrame(); // while (IsRecording()) // { // yield return endOfFrame; // } //} private IEnumerator EndRecordWithoutSaveData(float pitch, System.Action <bool, float> callback, Action playOver) { yield return(new WaitForSeconds(_Duration)); try { StopRecord(); //播放声音结束 bool result = IsTalked(); C_DebugHelper.LogErrorFormat("MicphoneSinglton EndRecordWithoutSaveData line287 ...result:" + result); if (callback != null) { callback(result, 1.0f); } #if UNITY_EDITOR result = false; #endif SpeechRecognizeSystemEvent.Instance.RemoveGetRecordStatusEvent(); SpeechRecognizeSystemEvent.Instance.DelayStop = null; if (!result) { #if UNITY_EDITOR //AudioManager.Instance.PlayerSound("public/sound/common_5.ogg",false,()=> { // AudioManager.Instance.SetPlayerSoundPitch(1.0f); // StopAllCoroutines(); // if (playOver != null) // { // playOver(); // } //}); SpeechRecognizeSystemEvent.Instance.StartDelayStop(_Duration, () => { AudioManager.Instance.SetPlayerSoundPitch(1.0f); StopAllCoroutines(); if (playOver != null) { playOver(); } }); #else AudioManager.Instance.SetPlayerSoundPitch(1.0f); StopAllCoroutines(); if (playOver != null) { playOver(); } #endif } else { #if UNITY_EDITOR AudioManager.Instance.PlayerSound("public/sound/common_5.ogg", false, () => { AudioManager.Instance.SetPlayerSoundPitch(1.0f); StopAllCoroutines(); if (playOver != null) { playOver(); } }); //SpeechRecognizeSystemEvent.Instance.StartDelayStop(_Duration, () => { // AudioManager.Instance.SetPlayerSoundPitch(1.0f); // StopAllCoroutines(); // if (playOver != null) // { // playOver(); // } //}); #else AudioManager.Instance.PlayerSoundModefyToneByClip(audio.clip, pitch, () => { C_DebugHelper.Log("EndRecordWithoutSaveData line 272: PlayerSoundModefyToneByClip over"); AudioManager.Instance.SetPlayerSoundPitch(1.0f); StopAllCoroutines(); if (playOver != null) { playOver(); } }); #endif } } catch (Exception e) { C_DebugHelper.Log("EndRecordWithoutSaveData line323:" + e); AudioManager.Instance.SetPlayerSoundPitch(1.0f); StopAllCoroutines(); if (playOver != null) { playOver(); } } finally { } yield return(null); }