public void 注销() { var __结果 = Dll在线.MSPLogout(); if (__结果 != (int)ErrorCode.MSP_SUCCESS) { throw new ApplicationException("注销失败! 错误码: " + __结果); } }
public void 登录(string appid) { var __登录参数 = string.Format("appid={0}, work_dir = .", appid); var __结果 = Dll在线.MSPLogin(string.Empty, string.Empty, __登录参数); if (__结果 != (int)ErrorCode.MSP_SUCCESS) { throw new ApplicationException("登录失败! 错误码: " + __结果); } }
public override void 设置语法(string 语法) { var __语法参数 = "dtt = abnf, sub = asr"; int __结果 = 0; var __语法长度 = Encoding.UTF8.GetBytes(语法).Length; var __编码 = Encoding.UTF8.GetBytes(语法 + '\0'); var __指针 = Dll在线.MSPUploadData("", __编码, (uint)__语法长度, __语法参数, ref __结果); if (__结果 != 0) { Debug.WriteLine("语法加载失败, 错误码: " + __结果); throw new ApplicationException("语法加载失败, 错误码: " + __结果); } _语法id = Marshal.PtrToStringAnsi(__指针); //Debug.WriteLine("语法id: " + _语法id); }
public override void 设置语法(List <string> 词典) { if (词典 == null || 词典.Count == 0) { return; } var __字符串 = 合成词典(词典); var __语法参数 = "sub = uup, dtt = userword"; int __结果 = 0; var __语法长度 = Encoding.UTF8.GetBytes(__字符串).Length; var __编码 = Encoding.UTF8.GetBytes(__字符串 + '\0'); Dll在线.MSPUploadData("", __编码, (uint)__语法长度, __语法参数, ref __结果); if (__结果 != 0) { Debug.WriteLine("语法加载失败, 错误码: " + __结果); throw new ApplicationException("语法加载失败, 错误码: " + __结果); } }
public IntPtr QISRSessionBegin(string grammarList, string _params, ref int errorCode) { return(Dll在线.QISRSessionBegin(grammarList, _params, ref errorCode)); }
public int MSPLogout() { return(Dll在线.MSPLogout()); }
public int MSPLogin(string user, string password, string configs) { return(Dll在线.MSPLogin(user, password, configs)); }
public int QISRSessionEnd(IntPtr sessionID, string hints) { return(Dll在线.QISRSessionEnd(sessionID, hints)); }
public IntPtr QISRGetResult(IntPtr sessionID, ref E识别状态 rsltStatus, int waitTime, ref int errorCode) { return(Dll在线.QISRGetResult(sessionID, ref rsltStatus, waitTime, ref errorCode)); }
public int QISRAudioWrite(IntPtr sessionID, byte[] waveData, uint waveLen, E音频块位置 audioStatus, ref E检测状态 epStatus, ref E识别状态 recogStatus) { return(Dll在线.QISRAudioWrite(sessionID, waveData, waveLen, audioStatus, ref epStatus, ref recogStatus)); }
public MemoryStream 合成(string __文本) { if (string.IsNullOrEmpty(__文本.Trim())) { throw new ApplicationException("请输入合成语音的内容!"); } IntPtr __session = IntPtr.Zero; try { int __结果 = 0; var __合成参数 = string.Format("voice_name = xiaoyan, text_encoding = gb2312, sample_rate = {0}, speed = 50, volume = 50, pitch = 50, rdn = 2", 音频采样率); __session = Dll在线.QTTSSessionBegin(__合成参数, ref __结果); if (__结果 != (int)ErrorCode.MSP_SUCCESS) { throw new ApplicationException("启动合成失败! 错误码: " + __结果); } __结果 = Dll在线.QTTSTextPut(__session, __文本, (uint)Encoding.Default.GetByteCount(__文本), string.Empty); if (__结果 != (int)ErrorCode.MSP_SUCCESS) { throw new ApplicationException("合成失败! 错误码: " + __结果); } var __数据流 = new MemoryStream(); __数据流.Write(new byte[44], 0, 44); var __解码状态 = E合成状态.进行中; while (true) { uint __解码长度 = 0; IntPtr __解码指针 = Dll在线.QTTSAudioGet(__session, ref __解码长度, ref __解码状态, ref __结果); if (__结果 != 0) { break; } byte[] __解码数据 = new byte[(int)__解码长度]; if (__解码指针 != IntPtr.Zero) { Marshal.Copy(__解码指针, __解码数据, 0, (int)__解码长度); } __数据流.Write(__解码数据, 0, __解码数据.Length); Thread.Sleep(100); if (__解码状态 == E合成状态.完毕) { break; } } //if (memoryStream.Length == 44) //{ // throw new ApplicationException("合成失败! 无音频 "); //} byte[] __文件头 = HWAVE文件头.获取((int)__数据流.Length - 44); __数据流.Position = 0L; __数据流.Write(__文件头, 0, __文件头.Length); __数据流.Position = 0L; return(__数据流); } finally { if (__session != IntPtr.Zero) { int __结果 = Dll在线.QTTSSessionEnd(__session, ""); if (__结果 != (int)ErrorCode.MSP_SUCCESS) { throw new ApplicationException("结束合成失败! 错误码: " + __结果); } } } }