【问题标题】:Sphinx Ubuntu 14 c++ sphinx_config.h not foundSphinx Ubuntu 14 c++ sphinx_config.h 未找到
【发布时间】:2015-03-29 15:22: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: %s\n", 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.

【问题讨论】:

  • 当您询问编译器问题时,请提供编译器输出,包括编译器命令行。您可以在 IDE 窗口中找到它。
  • @NikolayShmyrev 感谢您的回答!我已经添加了有问题的输出。希望对您有所帮助!

标签: c++ c ubuntu cmusphinx pocketsphinx


【解决方案1】:

我用这个 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)

【讨论】:

    【解决方案2】:

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

    整个pocketsphinx-5prealpha 需要sphinxbase-5pr​​ealpha 并且它们的默认安装前缀是/usr/local。我建议你从 /usr 中删除 sphinxbase。

    【讨论】:

    • 你必须在 Makefile 中定义 MODELDIR。像 CFLAGS += -DMODELDIR "/usr/share/pocketsphinx/model" 这样的东西。或者只是在源代码中硬编码 MODELDIR。
    • Tutorial 说: MODELDIR 宏是在 GCC 命令行上定义的,使用 pkg-config 从 PocketSphinx 配置中获取 modeldir 变量。在 Windows 上,您可以简单地将预处理器定义添加到代码中,例如:#define MODELDIR "c:/sphinx/model"
    猜你喜欢
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2020-03-27
    相关资源
    最近更新 更多