alphacep / vosk-api

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

Nodejs voice recognition crash without errors #1201

Open mohamed-bahaa21 opened 1 year ago

mohamed-bahaa21 commented 1 year ago

command line voice recognition chat bot program depends on packages as:

It crashes randomly while its running without any errors to trace or debug. I used PM2 and the memory usage was ~165MB !!! but couldn't trace anything further. the whole logs I have is:

LOG (VoskAPI:ReadDataFiles():model.cc:213) Decoding params beam=10 max-active=3000 lattice-beam=2
LOG (VoskAPI:ReadDataFiles():model.cc:216) Silence phones 1:2:3:4:5:6:7:8:9:10
LOG (VoskAPI:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 0 orphan nodes.
LOG (VoskAPI:RemoveOrphanComponents():nnet-nnet.cc:847) Removing 0 orphan components.
LOG (VoskAPI:ReadDataFiles():model.cc:248) Loading i-vector extractor from model/ivector/final.ie
LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:183) Computing derived variables for iVector extractor
LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:204) Done.
LOG (VoskAPI:ReadDataFiles():model.cc:282) Loading HCL and G from model/graph/HCLr.fst model/graph/Gr.fst
LOG (VoskAPI:ReadDataFiles():model.cc:303) Loading winfo model/graph/phones/word_boundary.int
nshmyrev commented 1 year ago

Hard to say what is PM2. There is no need to load model several times.

mohamed-bahaa21 commented 1 year ago

Hard to say what is PM2. There is no need to load model several times.

Just a process manager for node apps, yeah I only load it one time. the result is the same without PM2, randomly exits without any error.

nshmyrev commented 1 year ago

Ok, and what is your code? Were you able to run or code samples?

mohamed-bahaa21 commented 1 year ago

Ok, and what is your code? Were you able to run or code samples?

https://www.dropbox.com/s/6msf7pst9xunwq0/callbot_demo.rar?dl=0

lexasss commented 1 year ago

Same issue here (running on Win10, Node.js v18.12.1, VS 2022), but I can see the exception stack:

...
LOG (VoskAPI:ReadDataFiles():model.cc:303) Loading winfo model/graph/phones/word_boundary.int
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: spawn sox ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn sox',
  path: 'sox',
  spawnargs: [
    '-b',       '16',
    '--endian', 'little',
    '-c',       '1',
    '-r',       '16000',
    '-e',       'signed-integer',
    'default',  '-p'
  ]
}

It crashes immediately after printing out this line with "LOG .... \word_boundary.int"

My project dependencies:

  "dependencies": {
    "mic": "^2.1.2",
    "vosk": "^0.3.39"
  }
nshmyrev commented 1 year ago

Does our sample code work for you?

nshmyrev commented 1 year ago

@lexasss your error is about missing sox

lexasss commented 1 year ago

I just downloaded English model (vosk-model-small-en-us-0.15), extracted it into 'model' folder in my project tree. Indeed, there are no files ending with "sox" in this folder. Did I miss some step?

P.S. My index.js file is basically test_microphone.js file (with the only edit from var vosk = require('..'); to var vosk = require('vosk');).

nshmyrev commented 1 year ago

@lexasss sox binary is used by node mic module to record audio. You have to install it. Or you can use alternative node microphone module.

lexasss commented 1 year ago

Installing sox (0.1.0 )didn't help. I'll search for another solution. Thanks for the tips!

UPD: Probably, it was a wrong sox, and I need to go with SoX

UPD2: Yes, this solved all the problems, the mic example works now.