1

I'm on ubuntu 18.04 and i'm trying to run a .c file that came with an API called vosk that i just want to run . The issue is that the python script (which comes standard with the API) works without any problems but after compiling with make the .c file, called test_vosk.c, that they provide (so i didn't write it) to run the API:

#include <vosk_api.h>
#include <stdio.h>

int main() {
    FILE *wavin;
    char buf[3200];
    int nread, final;

    VoskModel *model = vosk_model_new("model");
    VoskRecognizer *recognizer = vosk_recognizer_new(model, 16000.0);

    wavin = fopen("test.wav", "rb");
    fseek(wavin, 44, SEEK_SET);
    while (!feof(wavin)) {
         nread = fread(buf, 1, sizeof(buf), wavin);
         final = vosk_recognizer_accept_waveform(recognizer, buf, nread);
         if (final) {
             printf("%s\n", vosk_recognizer_result(recognizer));
         } else {
             printf("%s\n", vosk_recognizer_partial_result(recognizer));
         }
    }
    printf("%s\n", vosk_recognizer_final_result(recognizer));

    vosk_recognizer_free(recognizer);
    vosk_model_free(model);
    fclose(wavin);
    return 0;
}

and running it by doing

./test_vosk

i get this error:

LOG (VoskAPI:ReadDataFiles():model.cc:206) Decoding params beam=10 max-active=3000 lattice-beam=2
LOG (VoskAPI:ReadDataFiles():model.cc:209) 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:CompileLooped():nnet-compile-looped.cc:345) Spent 0.0199881 seconds in looped compilation.
LOG (VoskAPI:ReadDataFiles():model.cc:233) 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:266) Loading HCL and G from model/graph/HCLr.fst model/graph/Gr.fst
LOG (VoskAPI:ReadDataFiles():model.cc:287) Loading winfo model/graph/phones/word_boundary.int
Segmentation fault (core dumped)

and happens a similar thing if i try to ./test_vosk_speaker (which is basically the same script but with another feature):

LOG (VoskAPI:ReadDataFiles():model.cc:206) Decoding params beam=10 max-active=3000 lattice-beam=2
LOG (VoskAPI:ReadDataFiles():model.cc:209) 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:CompileLooped():nnet-compile-looped.cc:345) Spent 0.0199001 seconds in looped compilation.
LOG (VoskAPI:ReadDataFiles():model.cc:233) 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:266) Loading HCL and G from model/graph/HCLr.fst model/graph/Gr.fst
LOG (VoskAPI:ReadDataFiles():model.cc:287) Loading winfo model/graph/phones/word_boundary.int
ERROR (VoskAPI:ReadConfigFile():parse-options.cc:462) Cannot open config file: spk-model/mfcc.conf
terminate called after throwing an instance of 'kaldi::KaldiFatalError'
  what():  kaldi::KaldiFatalError
Aborted (core dumped)

This API works with an other library called Kaldi and for example the error that comes from the ./test_vosk_speaker may hints to a problem related with it (which is strange as python works!). I'm still trying to learn linux but i really don't know where to even look for this things and if someone could help me it would be super helpful. Thanks in advance!

If it can help the Makefile that compiled the test_vosk.c was like this inside

INC_DIR=../src
CFLAGS=-I../src
LDFLAGS=-L../src -lvosk -ldl -lpthread -Wl,-rpath=../src

all: test_vosk test_vosk_speaker

test_vosk: test_vosk.o
    g++ $^ -o $@ $(LDFLAGS)

test_vosk_speaker: test_vosk_speaker.o
    g++ $^ -o $@ $(LDFLAGS)

%.o: %.c
    g++ $(CFLAGS) -c -o $@ $<

clean:
    rm -f *.o *.a test_vosk test_vosk_speaker

and the script in order to run needs a model put inside a folder in the same directory of test_vosk.c but if you don't do it and run ./test_vosk it doesn't find the model and this is the error that comes up:

LOG (VoskAPI:ReadDataFiles():model.cc:206) Decoding params beam=13 max-active=7000 lattice-beam=6
LOG (VoskAPI:ReadDataFiles():model.cc:209) Silence phones 1:2:3:4:5:6:7:8:9:10
ERROR (VoskAPI:ReadConfigFile():parse-options.cc:462) Cannot open config file: model/mfcc.conf
terminate called after throwing an instance of 'kaldi::KaldiFatalError'
  what():  kaldi::KaldiFatalError
Aborted (core dumped)
Birto
  • 71
  • 5
  • Have you tried catching the crash in a debugger to see where in *your* code it originates? What are the values of all involved variables in your code at the size and time of the crash? Are all possible pointers properly initialized? – Some programmer dude Jul 16 '21 at 08:40
  • I don't know anything about the quality of the libraries you use, but in general you should first assume a bug in your code. To debug a segmentation fault we need the source code. Apart from this, your error messages show "*Cannot open config file*". Maybe you should fix this problem first and check if the segmentation fault also occurs without this problem. You should [edit] your question and show some code that reproduces the problem the in form of a [mre]. – Bodo Jul 16 '21 at 08:47
  • Thanks to both for the tips, i edited the question and now it should be clearer. The script that i'm trying to run was provided by the API and i compiled it with the make that the authors wrote so the problem must be somewhere else then in the code (that i added) unfortunately. But i don't have any idea of where. – Birto Jul 16 '21 at 10:17
  • As you pointed in answer, your problem is due to using a `FILE *` without checking it's not `NULL`. – Mathieu Jul 16 '21 at 13:03

1 Answers1

1

i needed to put the python/exampe/test.wav to the /c folder. I wish this might be helpful for someone in the future.

Birto
  • 71
  • 5