引用dll
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void CallbackDelegate(int error, string info, UserData userData);
[DllImport("msc.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr QISRBuildGrammar(string grammarType, string grammarContent, IntPtr grammarLength, string param, CallbackDelegate callback, UserData userData);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class UserData
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40 /*User_Pass_MAX_SIZE*/)]
public string grammar_id;
[MarshalAs(UnmanagedType.SysUInt, SizeConst = 40 /*User_Pass_MAX_SIZE*/)]
public IntPtr build_fini;
[MarshalAs(UnmanagedType.SysUInt, SizeConst = 40 /*User_Pass_MAX_SIZE*/)]
public IntPtr update_fini;
[MarshalAs(UnmanagedType.SysUInt, SizeConst = 40 /*User_Pass_MAX_SIZE*/)]
public IntPtr errcode;
}
调用:
UserData udata = new UserData();
string bnf = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "call.bnf", Encoding.Default);
byte[] bytes = Encoding.Default.GetBytes(bnf);
bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8,bytes);
bnf = Encoding.UTF8.GetString(bytes);
IntPtr len = (IntPtr)bnf.Length;
IntPtr i = MSCDLL.QISRBuildGrammar("bnf", bnf, len,
"engine_type = local, asr_res_path = fo|res/asr/common.jet, sample_rate = 16000, grm_build_path = res/asr/GrmBuilld", callb, udata);
回调:
private void callb(int error, string info, UserData userData)
{
然后回调里的 error 是23300,语法构建失败。
}
你好,这个问题解决了吗?解决了可以分享一下你的代码吗?544462804@qq.com
朋友 这个问题解决了嘛 我也遇到这个问题了请教一下 1023043110@qq.com