在Ubuntu中对espeak-ng标头的未确定引用

时间:2017-10-31 04:33:16

标签: c++ ubuntu error-handling undefined-reference espeak

我已经下载了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,不知道如何解决它!我也搜索了很多,但无法理解解决方案:(

1 个答案:

答案 0 :(得分:2)

我让它正确编译尝试安装

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

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

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

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

的东西链接起来
 -lespeak