我正在尝试做口袋狮身人面像tutorial http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx在 C# 中使用 pinvoke 但当我尝试使用 ps_decode_raw() 进行解码时出现 AccessViolationException。
IntPtr ps = PocketSphinx.ps_init(config);
IntPtr fh = Win32Util.fopen(@"goforward.raw", "rb");
int rv = PocketSphinx.ps_decode_raw(ps, fh, "goforward", -1);
函数包装如下
//ps_decoder_t* ps_init(cmd_ln_t* config)
[DllImport("pocketsphinx.dll",
SetLastError = true,
CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr ps_init(
IntPtr config);
//int ps_decode_raw(ps_decoder_t *ps, FILE *rawfh, char const *uttid, long maxsamps);
[DllImport("pocketsphinx.dll",
SetLastError = true,
CallingConvention = CallingConvention.Cdecl)]
public extern static int ps_decode_raw(
IntPtr ps,
IntPtr rawfh,
[MarshalAs(UnmanagedType.LPStr)] string uttid,
int maxsamps);
[DllImport("msvcrt.dll",
SetLastError = true,
CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr fopen(
[MarshalAs(UnmanagedType.LPStr)] string _Filename,
[MarshalAs(UnmanagedType.LPStr)] string _Mode);
我也封装了 C 的 fopen,因为这是我能想到的实现本教程的最快方法。
我尝试在 ps 上调用 cmd_ln_retain 以确保 ps 不会导致问题。 (事实并非如此)。我还删除了上面的调试代码。
我很确定 fopen 出了问题,但我不确定是什么。
有人想要口袋狮身人面像日志。https://justpaste.it/h52t https://justpaste.it/h52t