public QueueItem(List <VoiceData> voiceBuffer, string session_begin_params, ref SendDataPipe sendDataPipe) { this.VoiceBuffer = voiceBuffer; this.Session_begin_params = session_begin_params; this.SendDataPipe = sendDataPipe; this.CompletionSource = new TaskCompletionSource <bool>(); }
public static Task RunIAT(List <VoiceData> VoiceReady, string session_begin_params, ref SendDataPipe SendDataPipe) { IntPtr session_id = IntPtr.Zero; string rec_result = string.Empty; string hints = "正常结束"; AudioStatus aud_stat = AudioStatus.ISR_AUDIO_SAMPLE_CONTINUE; EpStatus ep_stat = EpStatus.ISR_EP_LOOKING_FOR_SPEECH; RecogStatus rec_stat = RecogStatus.ISR_REC_STATUS_SUCCESS; int errcode = (int)ErrorCode.MSP_SUCCESS; session_id = MSCDLL.QISRSessionBegin(null, session_begin_params, ref errcode); if ((int)ErrorCode.MSP_SUCCESS != errcode) { Debug.WriteLine("\nQISRSessionBegin failed! error code:{0}\n", errcode); //return; } for (int i = 0; i < VoiceReady.Count(); i++) { aud_stat = AudioStatus.ISR_AUDIO_SAMPLE_CONTINUE; if (i == 0) { aud_stat = AudioStatus.ISR_AUDIO_SAMPLE_FIRST; } errcode = MSCDLL.QISRAudioWrite(PtrToStr(session_id), VoiceReady[i].data, (uint)VoiceReady[i].data.Length, aud_stat, ref ep_stat, ref rec_stat); if ((int)ErrorCode.MSP_SUCCESS != errcode) { MSCDLL.QISRSessionEnd(PtrToStr(session_id), null); } } errcode = MSCDLL.QISRAudioWrite(PtrToStr(session_id), null, 0, AudioStatus.ISR_AUDIO_SAMPLE_LAST, ref ep_stat, ref rec_stat); if ((int)ErrorCode.MSP_SUCCESS != errcode) { Debug.WriteLine("\nQISRAudioWrite failed! error code:{0} \n", errcode); //return; } while (RecogStatus.ISR_REC_STATUS_SPEECH_COMPLETE != rec_stat) { IntPtr rslt = MSCDLL.QISRGetResult(PtrToStr(session_id), ref rec_stat, 0, ref errcode); if ((int)ErrorCode.MSP_SUCCESS != errcode) { Debug.WriteLine("\nQISRGetResult failed, error code: {0}\n", errcode); break; } if (IntPtr.Zero != rslt) { string tempRes = PtrToStr(rslt); rec_result = rec_result + tempRes; if (rec_result.Length >= BUFFER_SIZE) { Debug.WriteLine("\nno enough buffer for rec_result !\n"); break; } } } //结果 Debug.WriteLine(rec_result); SendDataPipe.Start(rec_result); int errorcode = MSCDLL.QISRSessionEnd(PtrToStr(session_id), hints); if ((int)ErrorCode.MSP_SUCCESS == errorcode) { Debug.WriteLine("\nQISRGetResult successfull, {0}\n", hints); } return(Task.FromResult(rec_result)); }