首页 新闻 会员 周边 捐助

C# 调用科大讯飞 离线语音识别,构建语法失败。有大佬做过吗,给个例子吧。。。。

0
悬赏园豆:100 [待解决问题]

引用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,语法构建失败。
}

码吗的主页 码吗 | 初学一级 | 园豆:84
提问于:2020-06-15 20:46
< >
分享
所有回答(1)
0

你好,这个问题解决了吗?解决了可以分享一下你的代码吗?544462804@qq.com

StrayHeart | 园豆:202 (菜鸟二级) | 2020-10-09 16:13

朋友 这个问题解决了嘛 我也遇到这个问题了请教一下 1023043110@qq.com

支持(0) 反对(0) Allennn | 园豆:200 (初学一级) | 2020-12-23 10:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册