sandrohanea / whisper.net

Whisper.net. Speech to text made simple using Whisper Models
MIT License
512 stars 78 forks source link

Failed to load native whisper library #65

Open milanstamenkovic opened 1 year ago

milanstamenkovic commented 1 year ago

I can't get it work, I keep getting error "Failed to load native whisper library". Not sure if I'm supposed to do something rather then adding packages in project, downloading model and creating processor. I'm doing exactly what is done in Simple example. The error appears at following line: using var whisperFactory = WhisperFactory.FromPath("ggml-base.bin");

I'm integrating into dotnet core 5 application running on linux-x64 machine. Should I manually run whisper library or add it somewhere? Not sure that I understand the process at all..

`

    // This section detects whether the "ggml-base.bin" file exists in our project disk. If it doesn't, it downloads it from the internet
    if (!System.IO.File.Exists(modelFileName))
    {
      await DownloadModel(modelFileName, ggmlType);
    }

    // This section creates the whisperFactory object which is used to create the processor object.
    using var whisperFactory = WhisperFactory.FromPath("ggml-base.bin");

    // This section creates the processor object which is used to process the audio file, it uses language `auto` to detect the language of the audio file.
    using var processor = whisperFactory.CreateBuilder()
        .WithLanguage("auto")
        .Build();

`

sandrohanea commented 1 year ago

Hello @milanstamenkovic,

Did you also install the Runtime package with the same version?

e.g

    <PackageReference Include="Whisper.net" Version="1.4.3" />
    <PackageReference Include="Whisper.net.Runtime" Version="1.4.3" />
sandrohanea commented 1 year ago

If you installed that, or try to run the examples without success, the most likely issue is that you're missing glibc dependency.

milanstamenkovic commented 1 year ago

Hi @sandrohanea, Thanks on a quick response!

I installed both packages, but didn't know about glibc and it seems that it wasn't installed. I just installed glibc and then tried again but the same error appears: Full error is:

System.Exception: Failed to load native whisper library. Error: Unknown error at Whisper.net.WhisperFactory..ctor(IWhisperProcessorModelLoader loader, Boolean delayInit, String libraryPath, Boolean bypassLoading) at Whisper.net.WhisperFactory.FromPath(String path, Boolean delayInitialization, String libraryPath, Boolean bypassLoading)

Not sure if by "missing glibc dependency", You meant to install it in ubuntu.

sandrohanea commented 1 year ago

Hello, Yes, It is a dependency of the runtime (to be installed on the os). Checked more details here: https://github.com/sandrohanea/whisper.net/issues/11

milanstamenkovic commented 1 year ago

Hi @sandrohanea , First, I apologize for not going through closed issues, I didn't see filter for only opened issues. I'm still in the battle with this one.

Taking your steps to see which library is missing I found that I'm missing GLIB_2.32 and GLIBC_2.34. As I found out, it is not recommended to mess with those dependencies so I tried to upgrade ubuntu packages but that didn't do anything. I deployed code to server which is running Ubuntu 20.04.5 LTS and it throws the same error.

As I can see here I recompiled whistler.cpp and replaced the original file.. I'm not sure where this original file should be, I checked everything that is installed with Whisper.net and Whisper.net.Runtime and I couldn't find where I should replace it.

Because I don't have previous experience with this kind of integration, can You please confirm that I'm doing everything that is needed:

  1. Install Whisper.net
  2. Install Whisper.net.Runtime
  3. Consume them in code

Is regular workflow expected to be this way or there is something else under the hood? Thanks in Advance!

sandrohanea commented 1 year ago

Hello @milanstamenkovic, Yes, regular flow is expected to be like you described (those 3 steps).

You don't need to rebuild the library, just to ensure that the native library can be loaded. You can use ldd tool on Linux in order to find which dependency you are missing.

Once Whisper.net.Runtime is added to a project, in the output (e.g. bin/debug) you will see a directory runtimes, in that, you have linux-x64 which contains whisper.so.

Navigate to that path and execute ldd whisper.so in order to see the list of dependencies and where they are on your system.

This is not a normal flow as usually all the dependencies are automatically provisioned in most of the distributions.

pkese commented 1 year ago

I've found out providing custom whisper.so library will work only if I specify full path to that file in the program's environment:

LD_LIBRARY_PATH=$(pwd)/bin/x64/Debug/net6.0/runtimes/linux-x64/:$LD_LIBRARY_PATH dotnet watch run

Otherwise I always got System.DllNotFoundException

csharpfritz commented 1 year ago

In working with containers, I found that I needed to be sure to include the latest GLIBC libraries, and using a base image of Ubuntu 22.04 (Jammy) solved this problem for me

sandrohanea commented 1 year ago

Hello all, Last version 1.4.4 which was just published on nuget is working with older glibc ( 2.31 ) For all the people still having issues with loading the native library, feel free to give it a try.

Also, VS 2019 redistributable is not required on Windows and not VS 2022 as before.

Ofc, on both platforms, the library is working with the latest GLIBC and/or latest VS.

xqiu commented 1 year ago

For me, the demo with clblast GPU, one need to download and copy clblast.dll to the exe directory, or somewhere in path, download from https://github.com/CNugteren/CLBlast/releases/tag/1.6.0 .

The demo with cublas GPU on windows, one need to download https://developer.nvidia.com/cuda-toolkit , and only need to install CUBLAS, CUDART runtime. Then copy the dlls from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin. The 3 needed dlls are : cublas64_12.dll , cublasLt64_12.dll and cudart64_12.dll

philippjbauer commented 1 year ago

@sandrohanea I got my application working without problems on macOS Ventura, Ubuntu 20.22 and Windows 11 ARM64.

Windows 11 on an x64 machine unfortunately fails with:

System.Exception: Failed to load native whisper library. Error: A dynamic link library (DLL) initialization routine failed.

I followed all suggestions in this and the other threads except for hunting down a GLIBC since it only relates to Linux as far as I can tell.

The suggestion to use a custom loader doesn't work with the provided code because the LoadLibraryEx method is missing a 3rd parameter and I have no idea what a valid uint dwFlags value might be. I tried 0 and 1 just to try but it didn't work with those.

I've been trying the "Simple" example with version 1.4.6 of the project packages on an up-to-date install of Win 11 that has VS 2022 installed (including C++ development package).

laanhca commented 9 months ago

same problem

sapoiuyt commented 9 months ago

same problem。env is windows 11, and user net 6.0 version.

abdulkadirbener commented 8 months ago

[[Failed to load native whisper library. Error: The specified module could not be found.] Same problem with Win11, x64, VisualStudio2022, C++ SDK and Runtime ok, .NetCore 7, Whisper.Net version 1.4.7

I created a console application from scratch, installed everything necessary, and then run it in debug mode: Resulted with error. The compiler was in AnyCpu mode. Then I changed to x64 (tested with debug + release modes): Then, sometimes I get this error and sometimes I don't. The ratio is approximately 1 to 5. If it fails 5 times, it works correctly once???.... I know it's meaningless, but that's how it is. I have no idea why. I tried everything written in other titles as well as what is written in this title. It does not work. Has anyone experienced similar problems? Did anyone find a solution?

Kuprich commented 8 months ago

Hello, I also have a similar problem. Unhandled exception. System.Exception: Failed to load native whisper library. I used the simplest implementation. PC: widows 10 x64, C++ SDK and Runtime. It seems like I installed everything

But on another computer the same project runs without errors. what could it be?

fwaris commented 8 months ago

running into a similar problem Windows 11, x64, Perhaps better diagnostics can help pinpoint the exact issue

fwaris commented 8 months ago

Issue is fixed for me. In my case I found that I did not have CUDA Toolkit 12 installed (I had 11.8)

I used the "Dependency Walker" tool to find the native library dependency issue. It has been useful on several occasions.

https://github.com/isindicic/DependencyWalker.Net

I dropped the "\whisper.net.runtime.cublas\1.4.7\build\win-x64\whisper.dll" file into the tool's gui and it pointed out that it could not find the cuda12_XX DLLs, which prompted me to install CUDA 12.

fwaris commented 8 months ago

BTW I was able to run whisper.net with CUDA support on Linux. Need to compile the whisper.cpp git submodule on the Linux box with make:

make clean
WHISPER_CUBLAS=1 make libwhisper.so -j

And then copy the shared library to 'runtimes' (renamed to whisper.so):

 cp ./libwhisper.so <path from root to runtimes>/runtimes/linux-x64/whisper.so

I also had to set the LD_LIBRARY_PATH variable to /runtimes/linux-x64/ to let the system find the shared library.

Note: don't use the main whisper.cpp repo to compile whisper as that may not be compatible. Use the one referenced from the Whisper.net repo as a git submodule.

sandrohanea commented 8 months ago

Yes, that should work. The problem which I had was that on my linux build machine, couldn't use CUDA to build the linux runtime.

It is still in my plan, and hopefully will make it automatically in Whisper.net.Cublas in the next release 1.5.0.

han1157 commented 6 months ago

I solved this problem by running VS with administrator privileges