From 0da23da6b23d25ceb78f0229132d8efb9f3d3781 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 3 Mar 2007 13:55:25 +0100 Subject: [PATCH] Added espeak as another speech synthesis engine. --- configure.in | 7 +++-- src/config/options.inc | 5 ++-- src/viewer/text/festival.c | 58 +++++++++++++++++++++++++------------- src/viewer/text/festival.h | 3 +- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/configure.in b/configure.in index cc5bd2aa1..9345f7813 100644 --- a/configure.in +++ b/configure.in @@ -93,11 +93,14 @@ if test "x$CONFIG_DOC" != xno; then fi fi +AC_PATH_PROGS(ESPEAK, "speak", [/usr/bin/speak]) 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(ESPEAK) +AC_SUBST(FESTIVAL) AC_SUBST(FLITE) +AC_DEFINE_UNQUOTED(ESPEAK, "$ESPEAK", [Espeak]) +AC_DEFINE_UNQUOTED(FESTIVAL, "$FESTIVAL", [Festival]) AC_DEFINE_UNQUOTED(FLITE, "$FLITE", [Flite]) AC_SUBST(ASCIIDOC_FLAGS) AC_SUBST(CONFIG_ASCIIDOC) diff --git a/src/config/options.inc b/src/config/options.inc index b28051a36..184a4ab1d 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -755,10 +755,11 @@ static struct option_info config_options_info[] = { N_("Speech.")), INIT_OPT_INT("document.speech", N_("Default speech system"), - "system", 0, 0, 1, 0, + "system", 0, 0, 2, 0, N_("Default speech system:\n" "0 is festival\n" - "1 is flite")), + "1 is flite\n" + "2 is espeak")), 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 f3e8cad10..0604d75ea 100644 --- a/src/viewer/text/festival.c +++ b/src/viewer/text/festival.c @@ -52,6 +52,7 @@ read_from_festival(struct fest *fest) #define FESTIVAL_SYSTEM 0 #define FLITE_SYSTEM 1 +#define ESPEAK_SYSTEM 2 static void write_to_festival(struct fest *fest) @@ -75,7 +76,7 @@ write_to_festival(struct fest *fest) return; data = doc->data[fest->line].chars; - if (festival.festival_or_flite == FESTIVAL_SYSTEM) { + if (festival.speech_system == FESTIVAL_SYSTEM) { add_to_string(&buf, "(SayText \""); /* UTF-8 not supported yet. Does festival support UTF-8? */ for (i = 0; i < len; i++) { @@ -113,11 +114,18 @@ init_festival(void) int out_pipe[2] = {-1, -1}; pid_t cpid; - festival.festival_or_flite = get_opt_int("document.speech.system"); - if (festival.festival_or_flite == FESTIVAL_SYSTEM) { + festival.speech_system = get_opt_int("document.speech.system"); + switch (festival.speech_system) { + case FESTIVAL_SYSTEM: + default: if (access(FESTIVAL, X_OK)) return 1; - } else { + break; + case FLITE_SYSTEM: if (access(FLITE, X_OK)) return 1; + break; + case ESPEAK_SYSTEM: + if (access(ESPEAK, X_OK)) return 1; + break; } if (c_pipe(in_pipe) || c_pipe(out_pipe)) { @@ -137,31 +145,40 @@ init_festival(void) return 1; } if (!cpid) { + unsigned char *program; + dup2(out_pipe[1], 1); dup2(in_pipe[0], 0); close(out_pipe[0]); close(in_pipe[1]); close(2); close_all_non_term_fd(); - if (festival.festival_or_flite == FESTIVAL_SYSTEM) { + switch (festival.speech_system) { + case FESTIVAL_SYSTEM: + default: execl(FESTIVAL, "festival", "-i", NULL); _exit(0); - } else { - do { - char line[1024]; - FILE *out; - - fgets(line, 1024, stdin); - out = popen(FLITE, "w"); - if (out) { - fputs(line, out); - pclose(out); - putchar(' '); - fflush(stdout); - } - } while (!feof(stdin)); - _exit(0); + case FLITE_SYSTEM: + program = FLITE; + break; + case ESPEAK_SYSTEM: + program = ESPEAK; + break; } + do { + char line[1024]; + FILE *out; + + fgets(line, 1024, stdin); + out = popen(program, "w"); + if (out) { + fputs(line, out); + pclose(out); + putchar(' '); + fflush(stdout); + } + } while (!feof(stdin)); + _exit(0); } else { close(out_pipe[1]); close(in_pipe[0]); @@ -175,6 +192,7 @@ init_festival(void) } #undef FESTIVAL_SYSTEM #undef FLITE_SYSTEM +#undef ESPEAK_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 ed8184be9..555efb205 100644 --- a/src/viewer/text/festival.h +++ b/src/viewer/text/festival.h @@ -1,4 +1,3 @@ - #ifndef EL__VIEWER_TEXT_FESTIVAL_H #define EL__VIEWER_TEXT_FESTIVAL_H @@ -10,7 +9,7 @@ struct fest { int line; int in; int out; - int festival_or_flite; + int speech_system; unsigned int running:1; };