0

我在 ubuntu 18.04 上,我正在尝试运行一个 .c 文件,该文件附带一个我只想运行的名为vosk的 API。问题是 python 脚本(API 附带的标准)没有任何问题,但是在使用它们提供make的 .c 文件(称为test_vosk.c)编译之后(所以我没有编写它)来运行 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;
}

并通过做来运行它

./test_vosk

我收到此错误:

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)

如果我尝试./test_vosk_speaker(这基本上是相同的脚本但具有另一个功能)会发生类似的事情:

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)

这个 API 与另一个名为Kaldi的库一起使用,例如来自./test_vosk_speaker可能的错误提示与它相关的问题(这很奇怪,因为 python 工作!)。我仍在尝试学习 linux,但我真的不知道在哪里寻找这些东西,如果有人可以帮助我,那将非常有帮助。提前致谢!

如果它可以帮助编译的Makefiletest_vosk.c里面是这样的

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

并且要运行的脚本需要将模型放在同一目录中的文件夹中,test_vosk.c但是如果您不这样做并运行./test_vosk它,它将找不到模型,这是出现的错误:

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)
4

1 回答 1

1

我需要将 python/exampe/test.wav 放到 /c 文件夹中。我希望这可能对将来的某人有所帮助。

于 2021-07-16T12:20:55.810 回答