diff --git a/configure.in b/configure.in index b55adb71..d3d6034c 100644 --- a/configure.in +++ b/configure.in @@ -96,6 +96,9 @@ fi AC_PATH_PROGS(FESTIVAL, "festival", [/usr/bin/festival]) AC_SUBST(FESTIVAL) AC_DEFINE_UNQUOTED(FESTIVAL, "$FESTIVAL", [Festival]) +AC_PATH_PROGS(FLITE, "flite", [/usr/bin/flite]) +AC_SUBST(FLITE) +AC_DEFINE_UNQUOTED(FLITE, "$FLITE", [Flite]) AC_SUBST(ASCIIDOC_FLAGS) AC_SUBST(CONFIG_ASCIIDOC) AC_SUBST(CONFIG_POD2HTML) @@ -1342,6 +1345,7 @@ EL_ARG_ENABLE(CONFIG_UTF8, utf-8, [UTF-8], [ --enable-utf-8 enable UTF-8 support]) EL_LOG_CONFIG(FESTIVAL, [festival], []) +EL_LOG_CONFIG(FLITE, [flite], []) AC_ARG_ENABLE(weehoofooboomookerchoo, [ diff --git a/src/config/options.inc b/src/config/options.inc index feed2cc7..b59f0afc 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -744,6 +744,15 @@ static struct option_info config_options_info[] = { "compress_empty_lines", 0, 0, N_("Compress successive empty lines to only one in displayed text.")), + INIT_OPT_TREE("document", N_("Speech"), + "speech", 0, + N_("Speech.")), + + INIT_OPT_INT("document.speech", N_("Default speech system"), + "system", 0, 0, 1, 0, + N_("Default speech system:\n" + "0 is festival\n" + "1 is flite")), INIT_OPT_TREE("document", N_("URI passing"), "uri_passing", OPT_SORT | OPT_AUTOCREATE, diff --git a/src/viewer/text/festival.c b/src/viewer/text/festival.c index f0b42b52..90cd2e1d 100644 --- a/src/viewer/text/festival.c +++ b/src/viewer/text/festival.c @@ -49,6 +49,9 @@ read_from_festival(struct fest *fest) NULL, NULL, fest); } +#define FESTIVAL_SYSTEM 0 +#define FLITE_SYSTEM 1 + static void write_to_festival(struct fest *fest) { @@ -71,7 +74,8 @@ write_to_festival(struct fest *fest) return; data = doc->data[fest->line].chars; - add_to_string(&buf, "(SayText \""); + if (festival.festival_or_flite == FESTIVAL_SYSTEM) + add_to_string(&buf, "(SayText \""); /* UTF-8 not supported yet. If festival support UTF-8? */ for (i = 0; i < len; i++) { unsigned char ch = (unsigned char)data[i].data; @@ -80,7 +84,9 @@ write_to_festival(struct fest *fest) add_char_to_string(&buf, '\\'); add_char_to_string(&buf, ch); } - add_to_string(&buf, "\")\n"); + if (festival.festival_or_flite == FESTIVAL_SYSTEM) + add_to_string(&buf, "\")"); + add_char_to_string(&buf, '\n'); w = safe_write(fest->out, buf.source, buf.length); if (w >= 0) { @@ -100,8 +106,12 @@ init_festival(void) int out_pipe[2] = {-1, -1}; pid_t cpid; - if (access(FESTIVAL, X_OK)) - return 1; + festival.festival_or_flite = get_opt_int("document.speech.system"); + if (festival.festival_or_flite == FESTIVAL_SYSTEM) { + if (access(FESTIVAL, X_OK)) return 1; + } else { + if (access(FLITE, X_OK)) return 1; + } if (c_pipe(in_pipe) || c_pipe(out_pipe)) { if (in_pipe[0] >= 0) close(in_pipe[0]); @@ -126,8 +136,22 @@ init_festival(void) close(in_pipe[1]); close(2); close_all_non_term_fd(); - execl(FESTIVAL, "festival", "-i", NULL); - _exit(0); + if (festival.festival_or_flite == FESTIVAL_SYSTEM) { + execl(FESTIVAL, "festival", "-i", NULL); + _exit(0); + } else { + char line[1024]; + char command[1200]; + + do { + fgets(line, 1024, stdin); + snprintf(command, 1200, "%s -t \"%s\"", FLITE, line); + system(command); + putchar(' '); + fflush(stdout); + } while (!feof(stdin)); + _exit(0); + } } else { close(out_pipe[1]); close(in_pipe[0]); @@ -139,6 +163,8 @@ init_festival(void) return 0; } } +#undef FESTIVAL_SYSTEM +#undef FLITE_SYSTEM void run_festival(struct session *ses, struct document_view *doc_view) diff --git a/src/viewer/text/festival.h b/src/viewer/text/festival.h index d0631bdc..ed8184be 100644 --- a/src/viewer/text/festival.h +++ b/src/viewer/text/festival.h @@ -10,6 +10,7 @@ struct fest { int line; int in; int out; + int festival_or_flite; unsigned int running:1; };