You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

149 lines
5.5 KiB

#pragma once
#define LX_DLL_CLASS_EXPORTS 1
#include "Online_onebox_api.h"
#include "WWSerialPortApi.h"
#include <iostream>
#include <cliext/list>
using namespace System;
using namespace cliext;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::Generic;
using namespace System::Collections;
using namespace std;
using namespace System::Threading;
using namespace mobvoi::sds;
#pragma comment(lib, "vsdllsdk6.lib")
#pragma managed
namespace SpeechSdkHelperCLR {
public ref class SpeechSdkHelper
{
public:
SpeechSdkHelper();
~SpeechSdkHelper();
//1.设置sdk的配置文件目录
//path所在的目录下要有mobvoi目录,path字符串中不包含"mobvoi"
//如果没有调用,或path为空,会在exe所在目录下找mobvoi目录
void SetSdkConfigPath(String ^ path);
//2.设置sdk的log开关
//on为true的时候,会输出log到txt文件中,txt文件在SetSdkConfigPath设定的目录下。
void SetSdkLogOn(bool on);
//3. 设置识别参数的接口,startRecognition前调用
//enablePartial,是否返回识别的中间结果?
////enablePartial为true时返回,即会有MOBVOI_SDS_CB_PARTIAL_TRANSCRIPT类型的回调。
////为false时,只返回最终识别结果,即只有MOBVOI_SDS_CB_FINAL_TRANSCRIPT类型的回调。
//enableVolume,是否输出音量大小信息
void SetRecognitionParams(bool enablePartial, bool enableVolume);
//4. 设置需要识别的关键词,非必须
//perfectKeywords完全匹配,
//partialKeywords部分匹配
void SetContext(String ^ perfectKeywords, String ^ partialKeywords);
//5. 启动识别的接口
//callback参数是回调接口。
//code是0代表成功,其他值是失败
//type为MOBVOI_SDS_CB_FINAL_TRANSCRIPT是语音识别结果,MOBVOI_SDS_CB_RESULT是语义理解和搜索的结果
//type和info的值
//SDK_INIT_ERROR info是初始化失败的信息
//MOBVOI_SDS_CB_ERROR info是识别出错的信息
//MOBVOI_SDS_CB_FINAL_TRANSCRIPT info是最终识别结果
//MOBVOI_SDS_CB_PARTIAL_TRANSCRIPT info是中间识别结果
//MOBVOI_SDS_CB_RESULT info是json数据
//MOBVOI_SDS_CB_VOLUME 音量大小
//出错时,info中会有错误码,含义如下:
//MOBVOI_SDS_SUCCESS 成功
//MOBVOI_SDS_ERR_INVALID_PARAM 参数有误,可能是必选参数不存在,或者存在不支持的可选参数
//MOBVOI_SDS_ERR_UNKNOWN_INTENT 不支持的 intent
//MOBVOI_SDS_ERR_INTERNAL_ERROR SDS 内部错误
//MOBVOI_SDS_ERR_BAD_STATE 非预期的SDS状态,比如用户未初始化便使用某个service
//MOBVOI_SDS_ERR_NETWORK_ERROR 网络错误
//MOBVOI_SDS_ERR_SERVER_ERROR 服务器内部错误
//MOBVOI_SDS_ERR_NO_SPEECH 没有检测到语音,可能用户没有说话
//MOBVOI_SDS_ERR_GARBAGE 无法识别当前语音内容
//MOBVOI_SDS_ERR_BAD_HOTWORD 无效的热词
//MOBVOI_SDS_ERR_BUF_FULL SDS 内部某缓冲区已满
//MOBVOI_SDS_ERR_LICENSE_DENIED SDS 服务被拒绝。对应的 Service 未授权,或者 license 已过期,或已超过当日允许的最大使用次数
delegate void ResultDelegate(int code, System::String ^ type, System::String ^ info);
bool StartRecognition(ResultDelegate ^ callback);
//6.停止识别
//immediate为true,会放弃本次识别的结果,快速停止。
//immediate为false,会返回截至到调用StopRecognition时的语音识别结果。
bool StopRecognition(bool immediate);
//7. 语音合成接口
//在语义理解和搜索完成之后调用
//ttsContent是要合成语音的文本内容,设置为""时播报默认内容(语义理解结果的json中的displayText的内容)。
//language ,朗读的语音,与speaker有相关性,参数值为""时,默认使用"Mandarin"
//"Mandarin"; 中文
//"English"; 英文
//"Cantonese"; 粤语
//speaker,朗读的人,参数值为""时,默认使用"cissy"
//cissy 中文女声(成熟)
//billy 中文男声
//lucy 中文童声
//tina 台湾女声
//dora 粤语女声
//angela 英文女声
//speed,朗读速度,参数值为""时,默认使用"1.0"
//取值为"1.0"、 "1.2" 、"1.4"等字符串, "1.0"是正常语速,数字越大速度越快
bool StartTts(System::String^ ttsContent, System::String^ language, System::String^ speaker, System::String^ speed);
//不设置参数时,默认合成MOBVOI_SDS_CB_RESULT返回的json中的displayText的文本,使用默认参数
bool StartTts();
//8.停止语音合成
bool StopTts();
//9. 识别效果增强接口
//设置说话人与麦克风的角度(麦克风和摄像头放的比较近,可用人与摄像头的角度来近似替代),以激活dsp算法,进行降噪处理。
//可以不调用,此时增强0度方向
static void SetBeamDir(System::String^ serialPortname, int dir);
//20 测试接口
int AddCli(int a, int b);
delegate void MessageDelegate(int number);
void TestDelegate(int number, MessageDelegate^ messageDelegate);
private:
void SetRecognitionParamsInner(int startSilence, int endSilence, bool enablePartial, bool enableVolume);
OnlineRecognizerHelper * mRecognizerPointer;
//OnlineRecognizerHelper::RecognizerCallBack * m_pCallback;
int mStartSilence;
int mEndSilence;
bool mEnablePartial;
bool mEnableVolume;
char* mPerfectContextStr;
char* mPartialContextStr;
OnlineTtsHelper * mTtsPointer;
System::String^ mLanguage;
System::String^ mSpeaker;
System::String^ mSpeed;
};
}