Ejemplo n.º 1
0
        public void AudioWrite(Stream stream)
        {
            int    size     = (int)stream.Length;
            IntPtr h        = UnmanagedManager.UnmanagedReader(stream, size);
            int    pcmCount = 0;
            IntPtr hnow     = h;
            int    audStat  = (int)AudioSample.MSP_AUDIO_SAMPLE_CONTINUE;

            while (true)
            {
                uint len = 6400;// 每次写入200ms音频(16k,16bit):1帧音频20ms,10帧=200ms。16k采样率的16位音频,一帧的大小为640Byte
                if (size <= 2 * len)
                {
                    len = (uint)size;
                }
                if (len <= 0)
                {
                    break;
                }
                if (0 == pcmCount)
                {
                    audStat = (int)AudioSample.MSP_AUDIO_SAMPLE_FIRST;
                }
                errorCode = ISEDLL.QISEAudioWrite(SessionID, h + pcmCount, len, audStat, ref _epstatus, ref _recstatus);
                pcmCount += (int)len;
                size     -= (int)len;
            }
            errorCode = ISEDLL.QISEAudioWrite(SessionID, h + pcmCount, 0, (int)AudioSample.MSP_AUDIO_SAMPLE_LAST, ref _epstatus, ref _recstatus);
        }
Ejemplo n.º 2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!string.IsNullOrEmpty(SessionID))
     {
         errorCode = ISEDLL.QISESessionEnd(SessionID, null);
     }
     errorCode = ISEDLL.MSPLogout();
 }
Ejemplo n.º 3
0
        public string GetAnswer()
        {
            uint resultLen = 0;

            while (recStatus != (int)RecStatus.MSP_REC_STATUS_COMPLETE)
            {
                Thread.Sleep(500);//要等到服务端生成结果,避免重复调用,因此建议异步使用
                IntPtr result = ISEDLL.QISEGetResult(SessionID, ref resultLen, ref _recstatus, ref errorCode);
                if (recStatus == (int)RecStatus.MSP_REC_STATUS_COMPLETE)
                {
                    return(UnmanagedManager.GetStringFromUnmanagedMemory(result));
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void Login(string appid)
        {
            string lgi_param = "appid = {0}";

            lgi_param = string.Format(lgi_param, appid);
            errorCode = ISEDLL.MSPLogin(null, null, lgi_param);
            if (errorCode == (int)ErrorCode.MSP_SUCCESS)
            {
                string ise_ssb_param = "sub=ise,category=read_sentence,language=en_us,aue=speex-wb;7,auf=audio/L16;rate=16000";
                var    hSessionID    = ISEDLL.QISESessionBegin(ise_ssb_param, null, ref errorCode);
                if (errorCode == (int)ErrorCode.MSP_SUCCESS)
                {
                    SessionID = UnmanagedManager.GetStringFromUnmanagedMemory(hSessionID);
                }
            }
        }
Ejemplo n.º 5
0
 public void TextPut(string text)
 {
     Text      = text;
     errorCode = ISEDLL.QISETextPut(SessionID, Text, textLen, null);
 }