snakers4 / silero-vad

Silero VAD: pre-trained enterprise-grade Voice Activity Detector
MIT License
3.38k stars 353 forks source link

Failed to compile C++ VAD example #451

Closed akmitrich closed 1 month ago

akmitrich commented 2 months ago

C++ VAD example

You have a great cpp test example for your VAD model. It is provided with clear explanations. In accordance with README I created a Dockerfile:

FROM gcc:12.2.0-bullseye
WORKDIR /root
RUN wget https://github.com/microsoft/onnxruntime/releases/download/v1.12.1/onnxruntime-linux-x64-1.12.1.tgz
RUN tar -xvzf onnxruntime-linux-x64-1.12.1.tgz
COPY silero_vad.onnx .
COPY silero-vad-onnx.cpp .
COPY wav.h .
RUN g++ silero-vad-onnx.cpp -I /root/onnxruntime-linux-x64-1.12.1/include/ -L /root/onnxruntime-linux-x64-1.12.1/lib/ -lonnxruntime  -Wl,-rpath,/root/onnxruntime-linux-x64-1.12.1/lib/ -o test
ENTRYPOINT [ "./test" ]

which is far from being optimal but it is ok for a quick test.

Failed to compile

During compilation it runs into error:

In file included from /usr/local/include/c++/12.2.0/bits/alloc_traits.h:33,                                                                                                                                 
                 from /usr/local/include/c++/12.2.0/ext/alloc_traits.h:34,                                                                                                                                  
                 from /usr/local/include/c++/12.2.0/bits/basic_string.h:39,                                                                                                                                 
                 from /usr/local/include/c++/12.2.0/string:53,                                                                                                                                              
                 from /usr/local/include/c++/12.2.0/bits/locale_classes.h:40,
                 from /usr/local/include/c++/12.2.0/bits/ios_base.h:41,
                 from /usr/local/include/c++/12.2.0/ios:42,
                 from /usr/local/include/c++/12.2.0/ostream:38,
                 from /usr/local/include/c++/12.2.0/iostream:39,
                 from silero-vad-onnx.cpp:1:
/usr/local/include/c++/12.2.0/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Ort::Session; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}]':
/usr/local/include/c++/12.2.0/bits/alloc_traits.h:635:19:   required from 'static void std::allocator_traits<std::allocator<void> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = Ort::Session; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; allocator_type = std::allocator<void>]'
/usr/local/include/c++/12.2.0/bits/shared_ptr_base.h:604:39:   required from 'std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; _Tp = Ort::Session; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]'
/usr/local/include/c++/12.2.0/bits/shared_ptr_base.h:971:16:   required from 'std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = Ort::Session; _Alloc = std::allocator<void>; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]'
/usr/local/include/c++/12.2.0/bits/shared_ptr_base.h:1712:14:   required from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; _Tp = Ort::Session; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]'
/usr/local/include/c++/12.2.0/bits/shared_ptr.h:464:59:   required from 'std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; _Tp = Ort::Session]'
/usr/local/include/c++/12.2.0/bits/shared_ptr.h:1009:14:   required from 'std::shared_ptr<typename std::enable_if<(! std::is_array< <template-parameter-1-1> >::value), _Tp>::type> std::make_shared(_Args&& ...) [with _Tp = Ort::Session; _Args = {Ort::Env&, const wchar_t*, Ort::SessionOptions&}; typename enable_if<(! is_array< <template-parameter-1-1> >::value), _Tp>::type = Ort::Session]'
silero-vad-onnx.cpp:112:49:   required from here
/usr/local/include/c++/12.2.0/bits/stl_construct.h:119:7: error: no matching function for call to 'Ort::Session::Session(Ort::Env&, const wchar_t*, Ort::SessionOptions&)'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With the same error it fails to compile in my local Ubuntu environment with other versions of g++, onnxruntime.

Need some directions

How to deploy Silero VAD model with C++?

IntendedConsequence commented 2 months ago

@akmitrich try changing std::wstring to std::string in the example code. Onnxruntime C/C++ api uses wchar_t for paths only on windows.

akmitrich commented 1 month ago

Thanks a lot. This did help me to build example. Also I have to get rid of L"..." string literals in the source code.

akmitrich commented 1 month ago

I have run test example for my random audio file. Test example works perfectly fine for the aforementioned gcc 12.2.0 and onnxruntime 1.12.0. Even better, it also works as fine for gcc 14.1.0 and recently released onnxruntime 1.18.0.