Ubuntu 中对 espeak-ng headers 的未定义引用

Undifined reference to espeak-ng headers in Ubuntu

我已经下载了 espeak-ng 1.1.49./configure make make install 它,并通过 espeak --stdout "this is a test" | paplay 测试成功并且有效。然后我尝试在我在互联网上找到的 C++ 代码 (testSpeak.cpp) 中使用它,如下所示:

#include <string.h>
#include <vector> 
#include </usr/local/include/espeak-ng/speak_lib.h> 

int samplerate; // determined by espeak, will be in Hertz (Hz)
const int buflength = 200; // passed to espeak, in milliseconds (ms)

std::vector<short> sounddata;

int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
    if (wav == NULL)
        return 1; // NULL means done.

    /* process your samples here, let's just gather them */
    sounddata.insert(sounddata.end(), wav, wav + numsamples);
    return 0; // 0 continues synthesis, 1 aborts 
}

int main(int argc, char* argv[] ) {
    char text[] = {"my name is espeak"};
    samplerate = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, buflength, NULL, 0);
    espeak_SetSynthCallback(&SynthCallback);
    espeak_SetVoiceByName("en"); 
    unsigned int flags=espeakCHARS_AUTO | espeakENDPAUSE;
    size_t size = strlen(text); 
    espeak_Synth(text, size + 1, 0, POS_CHARACTER, 0, flags, NULL, NULL); 
    espeak_Synchronize();

    /* in theory sounddata holds your samples now... */

    return 0; 
}

但是在尝试通过此命令使其可执行后:g++ testSpeak.cpp -o speaks 我收到了这些错误消息:

/tmp/ccR9O0vw.o: In function `main':
testSpeak.cpp:(.text+0x78): undefined reference to `espeak_Initialize'
testSpeak.cpp:(.text+0x90): undefined reference to `espeak_SetSynthCallback'
testSpeak.cpp:(.text+0x9c): undefined reference to `espeak_SetVoiceByName'
testSpeak.cpp:(.text+0xce): undefined reference to `espeak_Synth'
testSpeak.cpp:(.text+0xd2): undefined reference to `espeak_Synchronize'
collect2: error: ld returned 1 exit status

我知道问题出在链接上,但由于我是 Linux 的新手,不知道该如何解决!我也搜索了很多但无法理解解决方案:(

我让它编译正确尝试安装

sudo apt-get install espeak-data libespeak-dev espeak-ng

你的包含是

   #include </usr/local/include/espeak-ng/speak_lib.h> 

成功

   #include <espeak-ng/speak_lib.h>

你的编译命令是

g++ testSpeak.cpp -o speaks

改用这个

g++ -W -o speaks myEspeak.cpp -lespeak

来自我的参考不会编译它经过艰难的尝试,它可能在旧版本中不起作用,但使用您提供的代码并安装这些程序并更改您的包含代码将编译。我没有做太多我会找到一种方法将其存储到 .wav 文件中。

http://apexlogic.net/code-bank/c-2/espeak-basic-usage-example/

当你从共享库编译时,你需要link它看起来像

 -lespeak