alphacep / vosk-api

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

nodejs api dynamic linking error - looking for dylib in wrong place #596

Open himat opened 3 years ago

himat commented 3 years ago

I downloaded this vosk-api repo, and after installing vosk with pip3 install vosk, I then tried out the nodejs bindings. But the sample code failed to run:

❯ node demo/test_simple.js
/Users/hima/Downloads/vosk-api/nodejs/node_modules/ffi-napi/lib/dynamic_library.js:75
    throw new Error('Dynamic Linking Error: ' + err);
    ^

Error: Dynamic Linking Error: dlopen(/Users/hima/Downloads/vosk-api/nodejs/lib/osx-x86_64/libvosk.dylib, 2): image not found
    at new DynamicLibrary (/Users/hima/Downloads/vosk-api/nodejs/node_modules/ffi-napi/lib/dynamic_library.js:75:11)
    at Object.Library (/Users/hima/Downloads/vosk-api/nodejs/node_modules/ffi-napi/lib/library.js:47:10)
    at Object.<anonymous> (/Users/hima/Downloads/vosk-api/nodejs/index.js:84:21)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/hima/Downloads/vosk-api/nodejs/demo/test_simple.js:1:12)

Specifically, it's strange that it's looking for the .dylib file within this vosk-api directory /Users/hima/Downloads/vosk-api/nodejs/lib/osx-x86_64/libvosk.dylib. There is no such lib/ folder in this repo. Shouldn't it be looking for the dylib somewhere in my root system (such as where the pip installed package is)?

I did find where where pip installed package is by the way, but there is no .dylib file there either. There is a .dyld file though.

❯ ls /Users/hima/anaconda/lib/python3.6/site-packages/vosk
__init__.py  __pycache__/  libvosk.dyld*  vosk_cffi.py

How do I fix this?

solyarisoftware commented 3 years ago

Hi

before running demo/test_simple.js, did you run a npm install on the node base directory? The error could suggest the lack of the ffi-napi module.

Also, download a model.

himat commented 3 years ago

Yes, I already did a yarn install in the vosk-api/nodejs directory. And I do have the vosk-model-small-en-us-0.15 model in the same folder at vosk-api/nodejs/model and also in `vosk-api/nodejs/model/demo

The error shows that it's look for the dll in the wrong folder.

himat commented 3 years ago

Ok I tried the same test_simple.js file but in a separate directory where I installed vosk from npm and that worked properly. So I think probably your demo code needs to be updated when it's being run from within the folder.

nshmyrev commented 3 years ago

A valid issue.

solyarisoftware commented 3 years ago

I don't see a real problem here to be honest.

Ok I tried the same test_simple.js file but in a separate directory where I installed vosk from npm and that worked properly. So I think probably your demo code needs to be updated when it's being run from within the folder.

Yes. IMMO there are two way to use/test vosk:

A. you git clone this repo, so you have to:

  1. do npm install in the nodejs home directory (where the package.json is)
  2. do cd demo && node .... run demo program FROM the demo directory. Because the vosk package is here included from the parent duirectory include ('..')

B. you create your application (separate) directory and here you do a npm install vosk

nshmyrev commented 3 years ago

A. you git clone this repo, so you have to:

  1. do npm install in the nodejs home directory (where the package.json is)
  2. do cd demo && node .... run demo program FROM the demo directory. Because the vosk package is here included from the parent duirectory include ('..')

this doesn't work now, because it expects precompiled libs in lib folder. I shall try to fix it.

charlesjuliandev commented 2 years ago

Is this still the case or has this been resolved? I'm still getting the dynamic linking error.