【问题标题】:Undifined reference to espeak-ng headers in Ubuntu在 Ubuntu 中未定义对 espeak-ng 标头的引用
【发布时间】:2018-04-12 04:22:48
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    我可以正确编译尝试安装

    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/
    

    当你从一个共享库编译时,你需要将它与看起来像这样的东西链接起来

     -lespeak 
    

    【讨论】:

    猜你喜欢
    • 2023-03-27
    • 2014-05-24
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 2011-06-05
    • 2013-04-22
    • 1970-01-01
    相关资源
    最近更新 更多