During recognition I have to switch between grammars. After using a grammar, I don’t need it anymore, so I’m trying to free the last used grammar. This is the code I use:
The code above does switch between the grammars, but I have two issues:
ps_unset_search always returns an error (-1).
When I finally call ps_free, the app crashes. Visual Studio gives the error:
“A heap has been corrupted”. The error occur at the function ps_search_base_free, at the first line - ckd_free(search->name); Regarding the “name” variable, Visual Studio indicates “error reading characters of string”.
When I don’t use the ps_set_search api, I don’t have any issues with ps_free.
PS – I’m using PocketSphinx with C# binding, on Windows
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm sorry, it is hard to understand what is going on. You write you use C# with bindings but your code in C.
I've just tried the following code and it works fine
using System;
using System.IO;
using Pocketsphinx;
public class Test
{
public static void Main()
{
Config c = Decoder.DefaultConfig();
c.SetString("-hmm", "../../model/en-us/en-us");
c.SetString("-lm", "../../model/en-us/en-us.lm.bin");
c.SetString("-dict", "../../model/en-us/cmudict-en-us.dict");
Decoder d = new Decoder(c);
byte[] data = File.ReadAllBytes("../../test/data/goforward.raw");
d.StartUtt();
d.ProcessRaw(data, data.Length, false, false);
d.EndUtt();
Console.WriteLine("Result is '{0}'", d.Hyp().Hypstr);
foreach (Segment s in d.Seg()) {
Console.WriteLine(s);
}
string name = d.GetSearch();
Console.WriteLine("Search is {0}", name);
d.UnsetSearch(name);
d.SetLmFile("another_search", "../../model/en-us/en-us.lm.bin");
d.SetSearch("another_search");
name = d.GetSearch();
Console.WriteLine("Search is {0}", name);
data = File.ReadAllBytes("../../test/data/goforward.raw");
d.StartUtt();
d.ProcessRaw(data, data.Length, false, false);
d.EndUtt();
Console.WriteLine("Result is '{0}'", d.Hyp().Hypstr);
}
}
Can you please provide a better example to reproduce your issue?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I didn't know how to use them. There are no instructions. It took me more time to search the internet for the info on how to use them (and at the end I still don't know how) then to write my own PInvoke signatures, which work well.
Last edit: Oren G. 2018-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
During recognition I have to switch between grammars. After using a grammar, I don’t need it anymore, so I’m trying to free the last used grammar. This is the code I use:
The code above does switch between the grammars, but I have two issues:
“A heap has been corrupted”. The error occur at the function ps_search_base_free, at the first line - ckd_free(search->name); Regarding the “name” variable, Visual Studio indicates “error reading characters of string”.
When I don’t use the ps_set_search api, I don’t have any issues with ps_free.
PS – I’m using PocketSphinx with C# binding, on Windows
I'm sorry, it is hard to understand what is going on. You write you use C# with bindings but your code in C.
I've just tried the following code and it works fine
Can you please provide a better example to reproduce your issue?
I have found that the error was caused by the C# binding. By this code:
The error was fixed after changing the returned type from String to IntPtr.
I recommend you to use our official swig-created bindings.
I didn't know how to use them. There are no instructions. It took me more time to search the internet for the info on how to use them (and at the end I still don't know how) then to write my own PInvoke signatures, which work well.
Last edit: Oren G. 2018-01-28