"Fossies" - the Fresh Open Source Software Archive

Member "espeak-ng-1.51.1/docs/integration.md" (21 Jun 2022, 3079 Bytes) of package /linux/privat/espeak-ng-1.51.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

Using eSpeak NG as a library

Simple steps

  1. Ensure you have satisfied building dependencies

  2. To use eSpeak NG as a C library, create file test-espeak.c with following content:

     #include <espeak-ng/speak_lib.h>
     
     espeak_AUDIO_OUTPUT output = AUDIO_OUTPUT_SYNCH_PLAYBACK;
     char *path = NULL;
     void* user_data;
     unsigned int *identifier;
     
     int main(int argc, char* argv[]) {
       char voicename[] = {"English"}; // Set voice by its name
       char text[] = {"Hello world!"};
       int buflength = 500, options = 0;
       unsigned int position = 0, position_type = 0, end_position = 0, flags = espeakCHARS_AUTO;
       espeak_Initialize(output, buflength, path, options);
       espeak_SetVoiceByName(voicename);
       printf("Saying  '%s'...\n", text);
       espeak_Synth(text, buflength, position, position_type, end_position, flags, identifier, user_data);
       printf("Done\n");
       return 0;
     }
  3. Compile created file with command:

     gcc test-espeak.c -lespeak-ng -o test-espeak
  4. Run created binary with the command:

     ./test-espeak

Error solutions

If, during compilation, you get error like espeak-ng/speak_lib.h: No such file or directory, you may try to replace line:

#include <espeak-ng/speak_lib.h>

with

#include "/your/path/to/speak_lib.h"

where /your/path/to/ is actual path, where header file is located.

Additional info

Code above set library using just voice name with related language to it. Code below shows, how to set more detailed properties of the voice (e.g. language, variant and gender):

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

espeak_AUDIO_OUTPUT output = AUDIO_OUTPUT_SYNCH_PLAYBACK;
char *path = NULL;
void* user_data;
unsigned int *identifier;

int main(int argc, char* argv[] ) {
  char text[] = {"Hello world!"};
  int buflength = 500, options = 0;
  unsigned int position = 0, position_type = 0, end_position = 0, flags = espeakCHARS_AUTO;
  espeak_Initialize(output, buflength, path, options );
  espeak_VOICE voice;
  memset(&voice, 0, sizeof(espeak_VOICE)); // Zero out the voice first
  const char *langNativeString = "en"; // Set voice by properties
  voice.languages = langNativeString;
  voice.name = "US";
  voice.variant = 2;
  voice.gender = 2;
  espeak_SetVoiceByProperties(&voice);
  printf("Saying  '%s'...\n", text);
  espeak_Synth(text, buflength, position, position_type, end_position, flags, identifier, user_data);
  printf("Done\n");
  return 0;
}

Look for details at espeak_ng.h and speak_lib.h files.