C# Model.FindWord() method does not work for ANSI strings (for example Cyrillic)
- Dominant language
- Jupyter Notebook
- Stars
- 15.1k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
C# Model.FindWord() method does not work for ANSI strings.
For example:
```
var myword = "привет";
model.FindWord(myword); --not work
```
I found several solutions to this problem:
1)
```
var myword = "привет";
byte[] utf8Bytes = Encoding.UTF8.GetBytes(myword + "\0");
IntPtr ansiStringPtr = Marshal.AllocHGlobal(utf8Bytes.Length);
Marshal.Copy(utf8Bytes, 0, ansiStringPtr, utf8Bytes.Length);
string example1 = Marshal.PtrToStringAnsi(ansiStringPtr);
model.FindWord(example1); --work
```
2)
```
//fixing the error:
//System.NotSupportedException: "No data is available for encoding 1251. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method."
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var myword = "привет";
string example2 = Encoding.GetEncoding(1251).GetString(Encoding.UTF8.GetBytes(myword + "\0"));
model.FindWord(example2); --work
```
It may be necessary to add a new FindWordANSI() method.
And import from the library by specifying CharSet.Ansi:
```
[DllImport("libvosk", EntryPoint = "vosk_model_find_word", CharSet = CharSet.Ansi)] public static extern int Model_vosk_model_find_word_ansi(HandleRef jarg1, string jarg2);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.