/// <summary>
        /// 创建一句话识别对象.
        /// </summary>
        /// <returns>成功返回speechRecognizerRequest对象, 否则返回NULL.</returns>
        public SpeechRecognizerRequest CreateRecognizerRequest()
        {
            IntPtr request = NativeMethods.NlsCreateRecognizerRequest();
            SpeechRecognizerRequest SRrequest = new SpeechRecognizerRequest();

            SRrequest.native_request = request;
            return(SRrequest);
        }
Example #2
0
        /// <summary>
        /// 设置通道关闭回调函数, 在请求过程中通道关闭时, sdk内部线程上报该回调.
        /// </summary>
        /// <param name="request">
        /// CreateRecognizerRequest所建立的request对象.
        /// </param>
        /// <param name="callback">
        /// 用户传入的回调函数.
        /// </param>
        /// <param name="para">
        /// 用户对象.
        /// </param>
        /// <returns></returns>
        public void SetOnChannelClosed(
            SpeechRecognizerRequest request, CallbackDelegate callback, object para = null)
        {
            SpeechParamStruct user_param = new SpeechParamStruct();

            user_param.user     = para;
            user_param.callback = callback;
            user_param.nlsEvent = new NLS_EVENT_STRUCT();
            IntPtr toCppParam = Marshal.AllocHGlobal(Marshal.SizeOf(user_param));

            Marshal.StructureToPtr(user_param, toCppParam, false);
            NativeMethods.SROnChannelClosed(request.native_request, onRecognitionClosed, (IntPtr)toCppParam);
            return;
        }
Example #3
0
 /// <summary>
 /// 会与服务端确认关闭, 正常停止一句话识别操作. 异步操作, 失败返回TaskFailed.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int Stop(SpeechRecognizerRequest request)
 {
     return(NativeMethods.SRstop(request.native_request));
 }
Example #4
0
 /// <summary>
 /// 设置用户自定义ws阶段http header参数.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="key">
 /// 参数名称.
 /// </param>
 /// <param name="value">
 /// 参数内容.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int AppendHttpHeaderParam(SpeechRecognizerRequest request, string key, string value)
 {
     return(NativeMethods.SRappendHttpHeaderParam(request.native_request, key, value));
 }
Example #5
0
 /// <summary>
 /// 设置用户自定义参数.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 参数.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetContextParam(SpeechRecognizerRequest request, string value)
 {
     return(NativeMethods.SRsetContextParam(request.native_request, value));
 }
Example #6
0
 /// <summary>
 /// 设置输出文本的编码格式.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 编码格式 UTF-8 or GBK.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetOutputFormat(SpeechRecognizerRequest request, string value)
 {
     return(NativeMethods.SRsetOutputFormat(request.native_request, value));
 }
Example #7
0
 /// <summary>
 /// 设置音频数据采样率.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 目前支持16000, 8000. 默认是1600.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetSampleRate(SpeechRecognizerRequest request, int value)
 {
     return(NativeMethods.SRsetSampleRate(request.native_request, value));
 }
Example #8
0
 /// <summary>
 /// 设置字段enable_voice_detection设置.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 是否启动自定义静音检测, 可选, 默认是False. 云端默认静音检测时间800ms.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetEnableVoiceDetection(SpeechRecognizerRequest request, bool value)
 {
     return(NativeMethods.SRsetEnableVoiceDetection(request.native_request, value));
 }
Example #9
0
 /// <summary>
 /// 设置是否在后处理中添加标点.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 可选参数, 默认false.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetPunctuationPrediction(SpeechRecognizerRequest request, bool value)
 {
     return(NativeMethods.SRsetPunctuationPrediction(request.native_request, value));
 }
Example #10
0
 /// <summary>
 /// 设置是否在后处理中执行数字转换.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 可选参数, 默认false.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetInverseTextNormalization(SpeechRecognizerRequest request, bool value)
 {
     return(NativeMethods.SRsetInverseTextNormalization(request.native_request, value));
 }
Example #11
0
 /// <summary>
 /// 设置是否返回中间识别结果.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 可选参数, 默认false.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetIntermediateResult(SpeechRecognizerRequest request, bool value)
 {
     return(NativeMethods.SRsetIntermediateResult(request.native_request, value));
 }
Example #12
0
 /// <summary>
 /// 设置泛热词.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 定制泛热词id字符串.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetVocabularyId(SpeechRecognizerRequest request, string value)
 {
     return(NativeMethods.SRsetVocabularyId(request.native_request, value));
 }
Example #13
0
 /// <summary>
 /// 设置定制模型.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 定制模型id字符串.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetCustomizationId(SpeechRecognizerRequest request, string value)
 {
     return(NativeMethods.SRsetCustomizationId(request.native_request, value));
 }
Example #14
0
 /// <summary>
 /// 直接关闭一句话识别过程.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int Cancel(SpeechRecognizerRequest request)
 {
     return(NativeMethods.SRcancel(request.native_request));
 }
Example #15
0
 /// <summary>
 /// 设置字段max_end_silence.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 允许的最大结束静音, 可选, 单位是毫秒. 超出后服务端将会发送RecognitionCompleted事件, 结束本次识别.
 /// 需要先设置SetEnableVoiceDetection为true. 建议时间0~5秒.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetMaxEndSilence(SpeechRecognizerRequest request, int value)
 {
     return(NativeMethods.SRsetMaxEndSilence(request.native_request, value));
 }
Example #16
0
 /// <summary>
 /// 发送语音数据.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="data">
 /// 语音数据.
 /// </param>
 /// <param name="dataSize">
 /// 语音数据长度(建议每次100ms左右数据).
 /// </param>
 /// <param name="type">
 /// ENCODER_NONE 表示原始音频进行传递, 建议每次100ms音频数据,支持16K和8K;
 /// ENCODER_OPU 表示以定制OPUS压缩后进行传递, 只支持20ms 16K16b1c;
 /// ENCODER_OPUS 表示以OPUS压缩后进行传递, 只支持20ms, 支持16K16b1c和8K16b1c.
 /// </param>
 /// <returns>
 /// 成功则返回0, 失败返回-1.
 /// 由于音频格式不确定, 传入音频字节数和传出音频字节数, 无法通过比较判断成功与否, 故成功返回0.
 /// </returns>
 public int SendAudio(SpeechRecognizerRequest request, byte[] data, UInt64 dataSize, EncoderType type)
 {
     return(NativeMethods.SRsendAudio(request.native_request, data, dataSize, (int)type));
 }
Example #17
0
 /// <summary>
 /// 设置Socket接收超时时间.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 超时时间.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetTimeout(SpeechRecognizerRequest request, int value)
 {
     return(NativeMethods.SRsetTimeout(request.native_request, value));
 }
 /// <summary>
 /// 销毁一句话识别对象.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <returns></returns>
 public void ReleaseRecognizerRequest(SpeechRecognizerRequest request)
 {
     NativeMethods.NlsReleaseRecognizerRequest(request.native_request);
     return;
 }
Example #19
0
 /// <summary>
 /// 口令认证. 所有的请求都必须通过SetToken方法认证通过, 才可以使用.
 /// </summary>
 /// <param name="request">
 /// CreateRecognizerRequest所建立的request对象.
 /// </param>
 /// <param name="value">
 /// 申请的token字符串.
 /// </param>
 /// <returns>成功则返回0, 否则返回-1.</returns>
 public int SetToken(SpeechRecognizerRequest request, string value)
 {
     return(NativeMethods.SRsetToken(request.native_request, value));
 }