1

I am trying to pas some strings to espeak and it will say them by this code:

#include <string.h>
#include <malloc.h>
#include <espeak/speak_lib.h>
#include <iostream>

#include <stdlib.h>
#include <unistd.h>
//#include <cstring>
using namespace std;
int main()
{



    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"};

    int i=0;

    char text[11][200] {"hi ",
                        "This is...",
                        "you can ... ",
                        "I am ,,,, " ,
                        "you can ... ",
                        "hope you ... ",
                        "come in ... ",
                        "if you ... ",
                        "you will... ",
                        "I hope ... ",
                        "Take care "
                       };



    unsigned int Size,position=0, end_position=0, flags=espeakCHARS_AUTO, *unique_identifier;


    output = AUDIO_OUTPUT_PLAYBACK;

    espeak_Initialize(output, Buflength, path, Options );
    espeak_SetVoiceByName(Voice);
    const char *langNativeString = "en_US";
    espeak_VOICE voice= {0};

    voice.languages = langNativeString;
    voice.name = "US";
    voice.variant = 2;
    voice.gender = 1;
    //  Size = strlen(text)+1;


    for (;;)
    {



        for(i=0; i<11; i++)
        {
            Size = sizeof(text[i]);
            system("eog --fullscreen --disable-gallery --single-window 1.jpg &");
            usleep(3000000);

            espeak_Synth( text[i], Size, position, position_type, end_position, flags,
                          unique_identifier, user_data );
            espeak_Synchronize( );
            system("eog --fullscreen --disable-gallery --single-window 1.jpg &");
            usleep(3000000);

        }
//fflush(stdout);

    }

    return 0;
}

But I get segmentation fault(core dumped) error. I tried to debugging the code and this is the error : Cannot open file: ../sysdeps/posix/system.c that occurs in this line of code: system("eog --fullscreen --disable-gallery --single-window 1.jpg &"); . How can I fix this?

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • Does eog runs correctly outside your code? – marom Dec 15 '17 at 14:39
  • Initialize *all* your variables. – molbdnilo Dec 15 '17 at 14:47
  • @marom: yes I can compile and run `system(eog)` in other programs without errors. – Hasani Dec 15 '17 at 15:23
  • Possible duplicate of [I am trying to pass some strings trough espeak and it reads them but I get "segmentation fault"](https://stackoverflow.com/questions/47772076/i-am-trying-to-pass-some-strings-trough-espeak-and-it-reads-them-but-i-get-segm) – ntd Dec 15 '17 at 17:56

2 Answers2

1

You think to have 11 arrays(sentences) but you actually have only 10. These two

          "I am glad too meet you here "
          "you can see many science and technology products here ",

are actually just one since you miss the comma at the end

marom
  • 5,064
  • 10
  • 14
0

I did transport this part of code to outside of the main() function, and it works now without errors:

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"};

int i=0;
unsigned int Size,position=0, end_position=0, flags=espeakCHARS_AUTO, *unique_identifier;
Hasani
  • 3,543
  • 14
  • 65
  • 125
  • Your code is wrong, I already explained why [in your duplicate question](https://stackoverflow.com/questions/47772076/i-am-trying-to-pass-some-strings-trough-espeak-and-it-reads-them-but-i-get-segm). The fact that sometime it happens to work does not change the original statement. – ntd Dec 15 '17 at 17:51
  • Ok, please tell me which lines are useless and I can remove them? – Hasani Dec 15 '17 at 19:03