/// <summary> /// 本接口用来开始一路ISR会话,并在参数中指定本路ISR会话用到的语法列表,本次会话所用的参数等。 /// </summary> /// <param name="grammarList"></param> /// <param name="_params"></param> /// <returns>会话ID。</returns> public static string SessionBegin(string grammarList, string _params) { MspErrors result = 0; IntPtr ptr = QISRSessionBegin(grammarList, _params, out result); switch (result) { case MspErrors.MSP_SUCCESS: //成功 return(MarshalUtils.Ptr2Str(ptr)); break; case MspErrors.MSP_ERROR_NOT_INIT: throw new Exception("未初始化。"); case MspErrors.MSP_ERROR_INVALID_PARA: throw new Exception("无效的参数。"); case MspErrors.MSP_ERROR_NO_LICENSE: throw new Exception("开始一路会话失败。"); default: throw new Exception("QISR会话初始化失败,错误代码: " + result); } }
public static void End() { MspErrors result = QTTSFini(); if (result != MspErrors.MSP_SUCCESS) { throw new Exception("QTTSFini failed, error code is " + result); } }
public static void SessionEnd(string sessionId, string reason) { MspErrors result = QTTSSessionEnd(sessionId, reason); if (result != MspErrors.MSP_SUCCESS) { throw new Exception("结束TTS会话错误,错误代码:" + result); } }
public static void TextPut(string sessionID, string text, TtsSessionParameters parameters = null) { int length = Encoding.Unicode.GetByteCount(text); MspErrors result = QTTSTextPut(sessionID, text, (uint)length, (parameters == null) ? null : parameters.ToString()); if (result != MspErrors.MSP_SUCCESS) { throw new Exception("向服务器发送数据," + result); } }
public static string SessionBegin(TtsSessionParameters parameters) { MspErrors result = MspErrors.MSP_SUCCESS; string sessionId = MarshalUtils.Ptr2Str(QTTSSessionBegin(parameters.ToString(), ref result)); if (result != MspErrors.MSP_SUCCESS) { throw new Exception("初始化TTS会话时发生错误," + result); } return(sessionId); }
/// <summary> /// QISRInit应当在应用程序初始化时仅调用一次。 /// </summary> /// <param name="config"></param> public static void Init(TtsConfig config) { MspErrors result = QTTSInit(config.ToString()); switch (result) { case MspErrors.MSP_SUCCESS: //成功 break; case MspErrors.MSP_ERROR_CONFIG_INITIALIZE: throw new Exception("初始化TTS的config实例时出现错误。"); default: throw new Exception("QTTS初始化失败,错误代码: " + result); } }
static void CheckResult(MspErrors code) { switch (code) { case MspErrors.MSP_SUCCESS: //成功 return; case MspErrors.MSP_ERROR_NOT_INIT: throw new EngineNotInitException(); case MspErrors.MSP_ERROR_INVALID_HANDLE: throw new EngineInvalidHandleException(); case MspErrors.MSP_ERROR_INVALID_PARA: throw new EngineInvalidParaException(); case MspErrors.MSP_ERROR_NO_DATA: throw new EngineNoDataException(); case MspErrors.MSP_ERROR_INVALID_PARA_VALUE: throw new EngineInvalidParaValueException(); case MspErrors.MSP_ERROR_NO_LICENSE: throw new EngineNoLicenseException(); } }
public static byte[] AudioGet(string sessionID, ref SynthStatusEnums synthStatus) { int audioLength = 0; MspErrors result = MspErrors.MSP_SUCCESS; IntPtr pAudioData = QTTSAudioGet(sessionID, ref audioLength, ref synthStatus, ref result); if (result != MspErrors.MSP_SUCCESS) { throw new Exception("获取语音结果出错," + result); } if (audioLength < 0) { return(null); } byte[] audioData = new byte[audioLength]; if (audioLength > 0) { Marshal.Copy(pAudioData, audioData, 0, audioLength); } return(audioData); }
static extern IntPtr QTTSAudioGet(string sessionID, ref int audioLen, ref SynthStatusEnums synthStatus, ref MspErrors errorCode);
static extern IntPtr QTTSSessionBegin(string _params, ref MspErrors errorCode);
/// <summary> /// 使用指定的错误消息初始化 System.Exception 类的新实例。 /// </summary> /// <param name="result"></param> /// <param name="message">描述错误的消息。</param> public EngineException(MspErrors result, string message) : base(message) { this.Result = result; }
public static extern IntPtr QISRGetResult(string sessionID, out RecogStatusEnums rsltStatus, int waitTime, out MspErrors errorCode);
static extern IntPtr QISRSessionBegin(string grammarList, string _params, out MspErrors errorCode);
public static void AudioWrite(string sessionID, IntPtr waveData, uint waveLen, AudioStatus audioStatus, out EndPointStatusEnums epStatus, out RecogStatusEnums recogStatus) { MspErrors result = QISRAudioWrite(sessionID, waveData, waveLen, audioStatus, out epStatus, out recogStatus); CheckResult(result); }
/// <summary> /// 使用指定错误消息和对作为此异常原因的内部异常的引用来初始化 System.Exception 类的新实例。 /// </summary> /// <param name="result"></param> /// <param name="message">解释异常原因的错误消息。</param> /// <param name="innerException">导致当前异常的异常;如果未指定内部异常,则是一个 null 引用(在 Visual Basic 中为 Nothing)。</param> public EngineException(MspErrors result, string message, Exception innerException) : base(message, innerException) { this.Result = result; }
static extern string QISRUploadData(string sessionID, string dataName, byte[] data, uint dataLen, string parameters, out MspErrors errorCode);
/// <summary> /// 初始化 System.Exception 类的新实例。 /// </summary> /// <param name="result"></param> public EngineException(MspErrors result) : base(EnumHelper.GetName(typeof(MspErrors), result)) { this.Result = result; }