2

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!

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • Did you [install pcaudiolib for audio output](https://github.com/espeak-ng/espeak-ng#building)? – sehe Nov 23 '17 at 10:23
  • @sehe: Sorry, I didn't get any notification about your comments! No, I didn't. I will install it now. – Hasani Nov 23 '17 at 15:08

1 Answers1

3

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Sidenote: all of this already worked out of the box by just replacing `espeak-ng` with `espeak` in the include line and using `sudo apt-get install libespeak{1,-dev}`. You might want to stick to `libespeak` for this reason. – sehe Nov 23 '17 at 10:42
  • I did install `libpcaudio` and `./configure make make install` the `espeak-ng` again and compiled my code again without errors, but my program only gives me the text results not sound! – Hasani Nov 23 '17 at 20:14
  • whats the meaning of this line `LD_LIBRARY_PATH=/tmp/espeak-ng/src/.libs/:/usr/local/lib ./sotest ` ? what is `./sotest `? is it your program's name? did you put it inside `/etc/environment` ? – Hasani Nov 24 '17 at 13:00
  • [LD_LIBRARY_PATH](http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80), `./sotest` was my test program, I did not put "it" (? anything) in `/etc/environment` – sehe Nov 25 '17 at 09:36
  • Whats the meaning of `{1,-dev}` ? – Hasani Nov 26 '17 at 13:08
  • @Hasani sorry for late response, it's bash-style shell expansion. E.g. `abc{de,fg}` expands to `abcde abcfg` – sehe Jul 07 '23 at 11:01