alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.38k stars 1.04k forks source link

precompiled binary & Windows Chinese character decode #1409

Closed yinfan98 closed 12 months ago

yinfan98 commented 12 months ago

Hi, I am having some issues while using the C or C# API.

cd <KALDI_ROOT> git clone -b vosk --single-branch --depth=1 https://github.com/alphacep/kaldi /opt/kaldi cd kaldi/tools make openfst cub ./extras/install_openblas_clapack.sh cd ../src ./configure --mathlib=OPENBLAS_CLAPACK --shared make -j 10 online2 lm rnnlm cd ../.. git clone https://github.com/alphacep/vosk-api --depth=1 cd vosk-api/src KALDI_ROOT=<KALDI_ROOT> make

nshmyrev commented 12 months ago

Can I complete the compilation process by using the following code without separately compiling Kaldi?

You can compile this way, yes

Is the same compilation process required when using C#?

You can use precompiled binary too

yinfan98 commented 12 months ago

Thank you for your response, and where can I find the precompiled binary

nshmyrev commented 12 months ago

https://github.com/alphacep/vosk-api/releases/tag/v0.3.45

yinfan98 commented 12 months ago

I found that when using the C++ API, directly using printf to output Chinese characters in a Windows environment does not produce the correct results. This is because I obtained a UTF-8 encoded char* string. Therefore, I need to perform character encoding conversion to obtain the correct output. I referred to the response from #973 and modified the conversion code based on it.

973 I use this function to decoding UTF-8 to string, it works!

std::string UTF8ToString(const char* utf8Data)
{
    std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
    std::wstring wString = conv.from_bytes(utf8Data); // utf-8 => wstring

    std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>> convert(
        new std::codecvt<wchar_t, char, std::mbstate_t>("CHS"));
    std::string str = convert.to_bytes(wString); // wstring => string

    return str;
}