Sphinx Ubuntu 14 c++ sphinx_config.h not found

Sphinx Ubuntu 14 c++ sphinx_config.h not found

本文关键字:config not found sphinx Ubuntu c++ Sphinx      更新时间:2023-10-16

我已经在Ubuntu 14上安装了PocketSphinx,现在正试图创建一个简单的示例。我从官方网站Sphinx获取代码。

#include <pocketsphinx.h>
int
main(int argc, char *argv[])
{
    ps_decoder_t *ps;
    cmd_ln_t *config;
    FILE *fh;
    char const *hyp, *uttid;
        int16 buf[512];
    int rv;
    int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
             "-hmm", MODELDIR "/en-us/en-us",
             "-lm", MODELDIR "/en-us/en-us.lm.dmp",
             "-dict", MODELDIR "/en-us/cmudict-en-us.dict",
             NULL);
if (config == NULL)
    return 1;
ps = ps_init(config);
if (ps == NULL)
    return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL)
    return -1;
    rv = ps_start_utt(ps);
if (rv < 0)
    return 1;
    while (!feof(fh)) {
        size_t nsamp;
        nsamp = fread(buf, 2, 512, fh);
        rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
    }
    rv = ps_end_utt(ps);
if (rv < 0)
    return 1;
hyp = ps_get_hyp(ps, &score);
if (hyp == NULL)
    return 1;
printf("Recognized: %sn", hyp);
fclose(fh);
    ps_free(ps);
    cmd_ln_free_r(config);
return 0;
}

Qmake是

    QT       += core
QT       -= gui
TARGET = OpenCVQt
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
DEPENDPATH += /usr/local/lib
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/include/pocketsphinx
INCLUDEPATH += /usr/local/include/sphinxbase
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS +=-lpocketsphinx
LIBS += -lsphinxbase
LIBS += -lsphinxad
SOURCES += main.cpp

无法理解出了什么问题。我在/usr/local/include/sphinxbase中看到了sphinx_config.h。谢谢

  18:54:06: Starting: "/usr/bin/make" 
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
In file included from /usr/include/sphinxbase/cmd_ln.h:66:0,
                 from /usr/local/include/pocketsphinx/pocketsphinx.h:52,
                 from ../OpenCVQt/main.cpp:1:
/usr/include/sphinxbase/prim_type.h:88:27: fatal error: sphinx_config.h: No such file or directory
 #include <sphinx_config.h>
                           ^
compilation terminated.
make: *** [main.o] Error 1
18:54:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
18:54:06: Elapsed time: 00:01.

标头没有错误。现在新错误->

22:42:41: Running steps for project OpenCVQt...
22:42:41: Configuration unchanged, skipping qmake step.
22:42:41: Starting: "/usr/bin/make" 
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I/usr/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
../OpenCVQt/main.cpp: In function 'int main(int, char**)':
../OpenCVQt/main.cpp:14:22: error: 'MODELDIR' was not declared in this scope
              "-hmm", MODELDIR "/en-us/en-us",
                      ^
../OpenCVQt/main.cpp:15:30: error: expected ')' before string constant
              "-lm", MODELDIR "/en-us/en-us.lm.dmp",
                              ^
../OpenCVQt/main.cpp:16:32: error: expected ')' before string constant
              "-dict", MODELDIR "/en-us/cmudict-en-us.dict",
                                ^
../OpenCVQt/main.cpp:9:23: warning: unused variable 'uttid' [-Wunused-variable]
     char const *hyp, *uttid;
                       ^
../OpenCVQt/main.cpp: At global scope:
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argc' [-Wunused-parameter]
 main(int argc, char *argv[])
 ^
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argv' [-Wunused-parameter]
make: *** [main.o] Error 1
22:42:42: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
22:42:42: Elapsed time: 00:01.

我用这个CMake配置解决了这个问题:

cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
find_package(PkgConfig REQUIRED)
pkg_check_modules(POCKETSPHINX REQUIRED pocketsphinx)
pkg_check_modules(SPHINXBASE REQUIRED sphinxbase)
message(STATUS "SPHINXBASE_LIBRARIES => " "${SPHINXBASE_LIBRARIES}")
message(STATUS "POCKETSPHINX_LIBRARIES => " "${POCKETSPHINX_LIBRARIES}")
message(STATUS "POCKETSPHINX_INCLUDE_DIRS => " "${POCKETSPHINX_INCLUDE_DIRS}")
message(STATUS "SPHINXBASE_INCLUDE_DIRS => " "${SPHINXBASE_INCLUDE_DIRS}")
set(
  your_pocketsphinx_app_src
  your_pocketsphinx_app.cpp
  ...
)
add_executable(your_pocketsphinx_app your_pocketsphinx_app.cpp)
  set_property(TARGET your_pocketsphinx_app PROPERTY CXX_STANDARD 11)  
  target_include_directories(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_INCLUDE_DIRS})
  target_include_directories(your_pocketsphinx_app PUBLIC ${SPHINXBASE_INCLUDE_DIRS})
  target_compile_options(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_CFLAGS_OTHER})
  target_compile_options(your_pocketsphinx_app PUBLIC ${SPHINXBASE_CFLAGS_OTHER})
  target_link_libraries(your_pocketsphinx_app ${SPHINXBASE_LIBRARIES})
  target_link_libraries(your_pocketsphinx_app ${POCKETSPHINX_LIBRARIES})
# Binary to be installed.
install(TARGETS your_pocketsphinx_app DESTINATION bin)

您似乎在/usr/include中安装了sphinbase标头,而不是在/usr/local/include中。如果您有意以这种方式编译sphinbase,则需要在Makefile中添加-I/usr/include/sphinxbase,而不是-I/usr/local/include/sphinxbase

整体pocketsphinx-5prealpha需要sphinbase-5prealpha,默认安装前缀为/usr/local。我建议您从/usr/中删除鞘氨醇酶。