Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to pass a string to espeak-ng and it reads my string by sound!

What I have tried:

I searched and find this program and did a little modification to change it to English from Italian, 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 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
    espeak_VOICE voice;
	memset(&voice, 0, sizeof(espeak_VOICE)); // Zero out the voice first
	//voice.languages = langNativeString;
	//voice.name = "klatt";
	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;
}


Then I tried to change the code like this:

#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[] = {"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 = "en"; //Default to US English
    espeak_VOICE voice;
        memset(&voice, 0, sizeof(espeak_VOICE)); // Zero out the voice first
        voice.languages = langNativeString;
        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;
}
Posted
Updated 22-Nov-17 21:56pm
v3

1 solution

 
Share this answer
 
Comments
Member 13376650 23-Nov-17 3:50am    
Do you mean I must uncomment some of that lines? I did uncomment them and changed the code...but didn't work again(question edited)
Member 13376650 23-Nov-17 5:09am    
I couldn't find any help there!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900