gpt4 book ai didi

c++ - Ubuntu 中对 espeak-ng header 的 undefined reference

转载 作者:搜寻专家 更新时间:2023-10-31 02:08:51 27 4
gpt4 key购买 nike

我已经下载了 espeak-ng 1.1.49./configure make make install 它,并通过 espeak --stdout "this is a测试” | 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

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

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

当你从共享库编译时,你需要将它链接到类似的东西

 -lespeak 

关于c++ - Ubuntu 中对 espeak-ng header 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47027953/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com