Search code examples
c++espeak

Why my espeak-ng program doesn't say anything?


I want to pass a string to espeak-ng and it reads my string by sound!

I searched and found this program and did a little modification to change it to English from Italian(under the commented lines), but didn't work:

#include <string.h>
#include <malloc.h>
#include <espeak-ng/speak_lib.h>



espeak_POSITION_TYPE position_type;
espeak_AUDIO_OUTPUT output;
char *path=NULL;
int Buflength = 500, Options=0;
void* user_data;
t_espeak_callback *SynthCallback;
espeak_PARAMETER Parm;



//char Voice[] = {"lt+klatt2"};
 char Voice[] = {"English"};

char text[30] = {"this is a english test"};
unsigned int Size,position=0, end_position=0, flags=espeakCHARS_AUTO, *unique_identifier;




int main(int argc, char* argv[] ) 
{
    output = AUDIO_OUTPUT_PLAYBACK;
    int I, Run = 1, L;    
    espeak_Initialize(output, Buflength, path, Options ); 
    espeak_SetVoiceByName(Voice);
    //const char *langNativeString = "lt"; //Default to US English
    const char *langNativeString = "en"; //Default to US English
    espeak_VOICE voice;
    memset(&voice, 0, sizeof(espeak_VOICE)); // Zero out the voice first
    voice.languages = langNativeString;
    //voice.name = "klatt";
    voice.name = "US";
    voice.variant = 2;
    voice.gender = 1;
    espeak_SetVoiceByProperties(&voice);
    Size = strlen(text)+1;    
    printf("Saying  '%s'",text);
    espeak_Synth( text, Size, position, position_type, end_position, flags,
    unique_identifier, user_data );
    espeak_Synchronize( );
    printf("\n:Done\n"); 
    return 0;
}

What is the problem?

It compiles without errors and makes speaks as executable file but when I try ./speaks the result is:

Saying  'this is a english test'
:Done

Without voice!

EDIT: I asked my question in gitub and somebody said:

The path parameter of espeak_Initialize needs to point to the espeak-ng-data directory, or its parent directory. Alternatively, you can set the ESPEAK_DATA_PATH environment variable to point to that directory.

So I did add this line ESPEAK_DATA_PATH=/usr/local/share/espeak-ng-data to /etc/environment file but nothing happened!

Also I tried to change the path variable of the code to this(as I know the address is true) char *path="/usr/local/share/espeak-ng-data" but no voice again!


Solution

  • Ok, trying this out you need to first build & install libpcaudio.

    Then you configure & build espeak.

    Next, when you run, you might need to specify the library paths:

    LD_LIBRARY_PATH=/tmp/espeak-ng/src/.libs/:/usr/local/lib ./sotest 
    

    This then notified me of a problem:

    Error processing file '/usr/local/share/espeak-ng-data/phontab': No such file or directory.
    

    This tells me that libespeak-ng wants to be installed, due to hardcoded paths (of course the path itself can be modified using ./configure --prefix= etc.)

    I personally found that I had to do the LD_LIBRARY_PATH trick during building of all library artifacts, and had to run make many times in succession until finally it didn't report more errors.

    All this indicates that project maintenance is not very good. I've seen several segfaults even along the way.

    After finally successfully doing

    sudo make install
    

    Your test program finally runs and makes the expected sound.