Esempio n. 1
0
        /// <summary>
        /// 构造函数,初始化引擎,开Session
        /// </summary>
        /// <param name="config">初始化引擎的参数</param>
        /// <param name="sessionParameters">开session的参数</param>
        public IsrClient(IsrConfig config, string recog_grammar, string recog_params)
        {
            this.recog_grammar = recog_grammar;
            this.recog_params  = recog_params;

            IsrInterop.Init(config);
        }
Esempio n. 2
0
        /// <summary>
        /// 结束会话。
        /// </summary>
        public string Finish()
        {
            StringBuilder lastResult = new StringBuilder();

            int loop_count = 0;
            //获取余下的识别结果
            EndPointStatusEnums ep_status  = EndPointStatusEnums.ISR_EP_NULL;
            RecogStatusEnums    rec_status = RecogStatusEnums.ISR_REC_NULL;

            ///最后一块数据发完之后,循环从服务器端获取结果
            IsrInterop.AudioWrite(this.sessionId, IntPtr.Zero, 0, AudioStatus.ISR_AUDIO_SAMPLE_LAST, out ep_status, out rec_status);
            ///考虑到网络环境不好的情况下,需要对循环次数作限定
            while (this.rslt_status != RecogStatusEnums.ISR_REC_STATUS_SPEECH_COMPLETE && loop_count++ < 30)
            {
                string str = null;
                try
                {
                    str = IsrInterop.GetResult(sessionId, out rslt_status, waitTime);
                }
                catch (EngineNoDataException)
                {
                    break;
                }
                if (!string.IsNullOrEmpty(str))
                {
                    this.result.Append(str);
                    lastResult.Append(str);
                }
                System.Threading.Thread.Sleep(200);
            }

            return(lastResult.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// 添加音频文件。
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <param name="audio_status"></param>
        /// <param name="ep_status">端点检测(End-point detected)器所处的状态</param>
        public string AppendAudio(byte[] buffer, int offset, int length, AudioStatus audio_status, out EndPointStatusEnums ep_status)
        {
            if (length > BLOCK_LEN)
            {
                throw new ArgumentException("length超过了最大发送长度。", "length");
            }

            //返回部分结果
            string partResult = null;

            RecogStatusEnums rec_status;//识别器所处的状态

            Marshal.Copy(buffer, 0, ptrBuffer, length);

            ///开始向服务器发送音频数据
            IsrInterop.AudioWrite(sessionId, ptrBuffer, (uint)length, audio_status, out ep_status, out rec_status);
            ///服务器返回部分结果
            if (rec_status == RecogStatusEnums.ISR_REC_STATUS_SUCCESS)
            {//已经有结果缓存在MSC中了,可以获取了
                partResult = IsrInterop.GetResult(sessionId, out this.rslt_status, waitTime);
                if (!string.IsNullOrEmpty(partResult))
                {
                    this.result.Append(partResult);
                }
            }

            return(partResult);
        }
Esempio n. 4
0
        public void Dispose()
        {
            //结束会话,释放资源
            int ret = IsrInterop.QISRSessionEnd(sessionId, string.Empty);

            if (ptrBuffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(ptrBuffer);
            }
        }
Esempio n. 5
0
 public void Dispose()
 {
     IsrInterop.End();
 }
Esempio n. 6
0
 public void Open()
 {
     //开始一路会话,使用会话模式,使用引擎内置的语法进行识别
     this.sessionId = IsrInterop.SessionBegin(this.recog_grammar, this.recog_params);
 }
Esempio n. 7
0
 public string UploadData(string keywords)
 {
     return(IsrInterop.UploadData(this.sessionId, keywords));
 }