./speaks:加载共享库时出错:libespeak-ng.so.1:无法打开共享对象文件:没有这样的文件或目录

./speaks: error while loading shared libraries: libespeak-ng.so.1: cannot open shared object file: No such file or directory

我已经从 github 下载了 espeak-ng 的最新版本,并且下载了 ./autogen.sh ./configure make make install。 所以我写了一个测试程序,如下所示:

#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++ -W -o speaks espeak.cpp -lespeak-ng

但是当我尝试通过 ./speaks 运行 可执行文件时,我收到此错误消息:

./speaks: error while loading shared libraries: libespeak-ng.so.1: cannot open shared object file: No such file or directory

有什么问题?

我知道 libespeak-ng.so.1 在这里:/usr/local/lib/libespeak-ng.so.1

我通过将这两行添加到我的“/etc/environment”文件中解决了这个问题:

LD_LIBRARY_PATH=/usr/local/lib
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

在Ubuntu18.04上,这是由于库路径设置错误造成的。

您可以通过以下方式修复它: sudo ln -s /usr/local/lib/libespeak-ng.so.1 /usr/lib/libespeak-ng.so.1