Exemplo n.º 1
0
        /// <summary>
        /// 退出
        /// </summary>
        public static bool Logout()
        {
            ErrorCode errorCode = Msc.MSPLogout();

            if (errorCode != ErrorCode.MSP_SUCCESS)
            {
                Debug.Log("账号登录失败:(错误码)" + (int)errorCode);
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 退出
        /// </summary>
        public static bool Logout()
        {
            ErrorCode errorCode = Msc.MSPLogout();

            if (errorCode != ErrorCode.MSP_SUCCESS)
            {
                Console.WriteLine("账号登录失败:(错误码)" + (int)errorCode);
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="usr">用户名称</param>
        /// <param name="pwd">密码</param>
        /// <param name="paramter">传入参数</param>
        public static bool Login()
        {
            if (User.Equals("") || Pwd.Equals("") || Paramter.Equals(""))
            {
                Debug.Log("账户数据存在空的");
            }
            ErrorCode error = Msc.MSPLogin(User, Pwd, Paramter);

            if (error != ErrorCode.MSP_SUCCESS)
            {
                Debug.Log("账号登录失败:(错误码)" + (int)error);
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        private void ThreadStart()
        {
            ErrorCode   errorCode   = ErrorCode.MSP_SUCCESS;
            AudioStatus audioStatus = AudioStatus.MSP_AUDIO_SAMPLE_FIRST;
            EpStatus    epStatus    = EpStatus.MSP_EP_IN_SPEECH;
            RsltStatus  rsltStatus  = RsltStatus.MSP_REC_STATUS_SUCCESS;

            // 开始
            IntPtr ptr = Msc.QISRSessionBegin(null, @params, out errorCode);

            if (errorCode != ErrorCode.MSP_SUCCESS)
            {
                Console.WriteLine("开始识别出错:(错误码)" + (int)errorCode);
                Account.Logout();
                return;
            }

            int maxLength = 20480;
            int tims      = m_Datas.Length / maxLength;

            if ((m_Datas.Length % maxLength) != 0)
            {
                tims++;
            }


            for (int i = 0; i < tims; i++)
            {
                if (i == 0)
                {
                    audioStatus = AudioStatus.MSP_AUDIO_SAMPLE_FIRST;
                }
                else if (i == tims - 1)
                {
                    audioStatus = AudioStatus.MSP_AUDIO_SAMPLE_LAST;
                }
                else
                {
                    audioStatus = AudioStatus.MSP_AUDIO_SAMPLE_CONTINUE;
                }

                byte[] by = null;
                if ((m_Datas.Length - maxLength * i) >= maxLength)
                {
                    by = new byte[maxLength];
                }
                else
                {
                    by = new byte[(m_Datas.Length - maxLength * i)];
                }

                by = m_Datas.Skip(i * maxLength).Take(by.Length).ToArray();

                ErrorCode errorCode1 = Msc.QISRAudioWrite(ptr, by, (uint)by.Length, audioStatus, out epStatus, out rsltStatus);

                if (errorCode1 != ErrorCode.MSP_SUCCESS)
                {
                    Console.WriteLine("音频数据写入失败:(错误码)" + (int)errorCode1);
                    Account.Logout();
                    return;
                }
            }

            RsltStatus    status     = RsltStatus.MSP_REC_STATUS_INCOMPLETE;
            ErrorCode     errorCode2 = ErrorCode.MSP_SUCCESS;
            StringBuilder msg        = new StringBuilder();

            while (status != RsltStatus.MSP_REC_STATUS_COMPLETE)
            {
                IntPtr data = Msc.QISRGetResult(ptr, out status, 5000, out errorCode2);

                if (errorCode2 != ErrorCode.MSP_SUCCESS)
                {
                    Console.WriteLine("获取失败:(错误码)" + (int)errorCode2);
                    Account.Logout();
                    return;
                }

                if (data != null)
                {
                    msg.Append(Marshal.PtrToStringAnsi(data));
                }
                Thread.Sleep(200);
            }

            ErrorCode errorCode3 = Msc.QISRSessionEnd(ptr, "识别结束");

            if (errorCode3 != ErrorCode.MSP_SUCCESS)
            {
                Console.WriteLine("结束失败:(错误码)" + (int)errorCode3);
            }

            Data   = msg.ToString();
            isDown = true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 合成线程
        /// </summary>
        private void ThreadStart()
        {
            try {
                ErrorCode errorCode;
                IntPtr    ptr = Msc.QTTSSessionBegin(m_Params, out errorCode);

                if (errorCode != ErrorCode.MSP_SUCCESS)
                {
                    Debug.Log("开始合成出错:(错误码)" + (int)errorCode);
                    Account.Logout();

                    return;
                }

                ErrorCode errorCode1 = Msc.QTTSTextPut(ptr, m_Data, (uint)Encoding.Default.GetByteCount(m_Data), string.Empty);

                if (errorCode1 != ErrorCode.MSP_SUCCESS)
                {
                    Debug.Log("文本写入出错:(错误码)" + (int)errorCode);
                    Account.Logout();

                    return;
                }

                MemoryStream memoryStream = new MemoryStream();
                SynthStatus  synthStatus;
                ErrorCode    errorCode2;
                uint         length;

                while (true)
                {
                    IntPtr data = Msc.QTTSAudioGet(ptr, out length, out synthStatus, out errorCode2);

                    if (data != null)
                    {
                        if (length > 0)
                        {
                            byte[] vs = new byte[(int)length];

                            Marshal.Copy(data, vs, 0, (int)length);

                            memoryStream.Write(vs, 0, vs.Length);
                            Thread.Sleep(1000);
                        }
                    }
                    if (errorCode2 != ErrorCode.MSP_SUCCESS)
                    {
                        Debug.Log("获取音频出错:(错误码)" + (int)errorCode2);
                        Account.Logout();

                        return;
                    }

                    if (synthStatus == SynthStatus.MSP_TTS_FLAG_DATA_END)
                    {
                        break;
                    }
                }


                ErrorCode errorCode3 = Msc.QTTSSessionEnd(ptr, "合成结束");

                WAVE_Header wave_Header = getWave_Header((int)memoryStream.Length);
                byte[]      head        = StructToBytes(wave_Header);

                memoryStream.Position = 0L;
                memoryStream.Write(head, 0, head.Length);
                memoryStream.Position = 0L;

                if (errorCode3 != ErrorCode.MSP_SUCCESS)
                {
                    Debug.Log("结束合成音频出错:(错误码)" + (int)errorCode2);
                    Account.Logout();

                    return;
                }

                Account.Logout();

                isDown = true;
                Data   = memoryStream.GetBuffer();

                Debug.Log("合成完成");
            } catch (Exception e) {
                Debug.Log(e);
                Account.Logout();
            }
        }