protected override void OnError(string error) { if (m_sessionId != IntPtr.Zero) { MSCDLL.QISRSessionEnd(Marshal.PtrToStringAnsi(m_sessionId), null); } Clear(); base.OnError(error); }
protected IEnumerator WaitResult() { int errorCode = (int)Errors.MSP_SUCCESS; var audioState = AudioStatus.MSP_AUDIO_SAMPLE_FIRST; var epState = EpStatus.MSP_EP_LOOKING_FOR_SPEECH; var recState = RecogStatus.MSP_REC_STATUS_SUCCESS; AudioSave.Save(RecordSavePath, m_audioClip); var bytes = IFlyUtils.ConvertClipToBytes(m_audioClip); errorCode = MSCDLL.QISRAudioWrite(Marshal.PtrToStringAnsi(m_sessionId), bytes, (uint)bytes.Length, audioState, ref epState, ref recState); if ((int)Errors.MSP_SUCCESS != errorCode) { OnError(string.Format("write LAST_SAMPLE failed: {0}", errorCode)); } else { errorCode = MSCDLL.QISRAudioWrite(Marshal.PtrToStringAnsi(m_sessionId), null, 0, AudioStatus.MSP_AUDIO_SAMPLE_LAST, ref epState, ref recState); if ((int)Errors.MSP_SUCCESS != errorCode) { OnError(string.Format("write LAST_SAMPLE failed: {0}", errorCode)); } else { IntPtr resultPtr = IntPtr.Zero; string result = ""; while (recState != RecogStatus.MSP_REC_STATUS_COMPLETE) { resultPtr = MSCDLL.QISRGetResult(Marshal.PtrToStringAnsi(m_sessionId), ref recState, 0, ref errorCode); if ((int)Errors.MSP_SUCCESS != errorCode) { OnError(string.Format("QISRGetResult failed! error code: {0}", errorCode)); break; } Debug.Log("Get Result : " + Marshal.PtrToStringAnsi(resultPtr)); result += Marshal.PtrToStringAnsi(resultPtr); yield return(0); } if (errorCode == (int)Errors.MSP_SUCCESS) { OnResult(result); MSCDLL.QISRSessionEnd(Marshal.PtrToStringAnsi(m_sessionId), "normal"); OnEnd(""); Clear(); } } } }