Calling Flite From Another Program


TKF15H

Member
Joined
Jan 27, 2006
Messages
212
Hello,
I'm trying to get Flite to read out something and nothing I've tried works.

system("./flite -t \"Text\"");

fp = fopen("out.txt", "w");
fwrite( msg, 1, strlen(msg), fp );
fflush(fp);
fclose(fp);
system("./flite out.txt" );

execl( "./flite", "./flite", "-t", msg );

execl( "./flite", "./flite", "out.txt" );

Some of these crash, others don't do anything, others don't do anything and crash after a while. o_O
 
I have no way of testing this at the minute, but everything I've seen says the last parameter should be 0/NULL. Plus I don't think you need the ./

Try:

execl("/path/flite", "flite", "params", "go", "here", 0);
 
woops, in the code I always put the extra NULL, I just forgot to do so in the post. >_<
*tries again*

[edit]
Just tried execl("./flite", "flite", "out.txt", 0 );
On the first try nothing happend, on the second it crashed.
 
Note that execl shouldn't return - it replaces your program with the one you're executing. Maybe that's why it looked like it crashed?

If you want your program to continue afterwards, you may be better off using system as FluffyPanda said, or popen if you want to redirect input or output. If you still want to use exec (e.g. to redirect both input and output) you need to fork first - something like this:

Code:
pid_t pid = fork();
if (pid == -1) {
    // Error while forking
    perror("fork");
    exit(-1);
}
if (pid == 0) {
    // this is the child process
    execl("./flite","flite","out.txt",0);
    // error while execing - it's not meant to return...
    perror("execl");
    exit(-1);
}
// this is the parent process - wait for the child to finish
waitpid(pid, NULL, 0);
// ... and now do as you please

The only practical difference between the above code and calling 'system' is that system invokes the shell, while the above code invokes flite directly.
 
Note that execl shouldn't return - it replaces your program with the one you're executing. Maybe that's why it looked like it crashed?
When I said crashed, I meant, "black screen till I turn the thing off and on again." so I don't think that's the problem. Besides, if it were, at least I'd hear flite read out the text. I just get a black screen and no sound. :(
 
Back
Top