diff -u -r1.3 app_festival.c
--- app_festival.c	27 Jun 2003 23:02:52 -0000	1.3
+++ app_festival.c	2 Jul 2003 05:36:38 -0000
@@ -16,6 +16,7 @@
 #include <asterisk/logger.h>
 #include <asterisk/channel.h>
 #include <asterisk/pbx.h>
+#include <asterisk/options.h>
 #include <asterisk/module.h>
 #include <asterisk/md5.h>
 #include <asterisk/config.h>
@@ -43,12 +44,21 @@
 
 static char *app = "Festival";
 
-static char *synopsis = "Say text to the user";
+static char *app_bg = "FestivalBG";
+
+static char *synopsis = "Say text to the user without interruption";
+
+static char *synopsis_bg = "Say text to the user allowing interruption";
 
 static char *descrip = 
-"  Festival(text[|intkeys]):  Connect to Festival, send the argument, get back the waveform,"
-"play it to the user, allowing any given interrupt keys to immediately terminate and return\n"
-"the value.\n";
+"  Festival(text):  Connect to Festival, send the argument, get back the waveform,\n"
+"play it to the user. The user will not be able to interrupt the stream by\n"
+"pressing a key similar to the 'Playback' application.\n";
+
+static char *descrip_bg = 
+"  FestivalBG(text):  Connect to Festival, send the argument, get back the waveform,\n"
+"play it to the user. The user can interrupt the stream at any time with a DTMF\n"
+"key similar to the 'Background' application. The key's value will be returned.\n";
 
 STANDARD_LOCAL_USER;
 
@@ -122,7 +132,7 @@
 }
 
 
-static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length) {
+static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, int ignoredtmf) {
 	int res=0;
 	int fds[2];
 	int rfds[1 + AST_MAX_FDS];
@@ -163,6 +173,8 @@
 		/* Order is important -- there's almost always going to be mp3...  we want to prioritize the
 		   user */
 		rfds[AST_MAX_FDS] = fds[0];
+		if (chan->_state != AST_STATE_UP) 
+			res = ast_answer(chan);
 		for (;;) {
 			CHECK_BLOCKING(chan);
 			for (x=0;x<AST_MAX_FDS;x++) 
@@ -188,10 +200,12 @@
 					break;
 				}
 				if (f->frametype == AST_FRAME_DTMF) {
-					ast_log(LOG_DEBUG, "User pressed a key\n");
+					if (option_verbose > 2)
+						ast_verbose(VERBOSE_PREFIX_3 "User pressed key %c\n", f->subclass);
+					res = f->subclass;
 					ast_frfree(f);
-					res = 0;
-					break;
+					if (!ignoredtmf)
+						break;
 				}
 				ast_frfree(f);
 			} else if (res == fds[0]) {
@@ -223,12 +237,14 @@
 						break;
 					}
 					if (res < sizeof(myf.frdata)) { // last frame
-						ast_log(LOG_WARNING, "Last frame\n");
+						if (option_verbose > 2)
+							ast_verbose(VERBOSE_PREFIX_3 "Last frame\n");
 						res=0;
 						break;
 					}
 				} else {
-					ast_log(LOG_WARNING, "No more waveform\n");
+					if (option_verbose > 2)
+						ast_verbose(VERBOSE_PREFIX_3 "No more waveform\n");
 					res = 0;
 				}
 			} else {
@@ -244,16 +260,14 @@
 //		kill(pid, SIGKILL);
 	if (!res && owriteformat)
 		ast_set_write_format(chan, owriteformat);
+	
 	return res;
 }
 
 #define MAXLEN 180
 #define MAXFESTLEN 2048
 
-
-
-
-static int festival_exec(struct ast_channel *chan, void *data)
+static int festival_exec(struct ast_channel *chan, void *data, int ignoredtmf)
 {
 	int usecache;
 	int res=0;
@@ -319,7 +333,8 @@
 		return -1;
 	}
 	LOCAL_USER_ADD(u);
-	ast_log(LOG_WARNING, "Text passed to festival server : %s\n",(char *)data);
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_3 "Text passed to festival server : %s\n",(char *)data);
 	/* Connect to local festival server */
 	
     	fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -376,7 +391,8 @@
     			}
     		} else {
     			read(fdesc,&strln,sizeof(int));
-    			ast_log(LOG_WARNING,"Cache file exists, strln=%d, strlen=%d\n",strln,strlen((char *)data));
+			if (option_verbose > 2)
+    				ast_verbose(VERBOSE_PREFIX_3 "Cache file exists, strln=%d, strlen=%d\n",strln,strlen((char *)data));
     			if (strlen((char *)data)==strln) {
     				ast_log(LOG_WARNING,"Size OK\n");
     				read(fdesc,&bigstring,strln);
@@ -394,9 +410,11 @@
 	if (readcache==1) {
 		close(fd);
 		fd=fdesc;
-		ast_log(LOG_WARNING,"Reading from cache...\n");
+		if (option_verbose > 2)
+			ast_verbose(VERBOSE_PREFIX_3 "Reading synthesized speech from cache...\n");
 	} else {
-		ast_log(LOG_WARNING,"Passing text to festival...\n");
+		if (option_verbose > 2)
+			ast_verbose(VERBOSE_PREFIX_3 "Passing text to festival...\n");
     		fs=fdopen(dup(fd),"wb");
 		fprintf(fs,festivalcommand,(char *)data);
 		fflush(fs);
@@ -405,7 +423,8 @@
 	
 	/* Write to cache and then pass it down */
 	if (writecache==1) {
-		ast_log(LOG_WARNING,"Writing result to cache...\n");
+		if (option_verbose > 2)
+			ast_verbose(VERBOSE_PREFIX_3 "Saving synthesized speech to cache...\n");
 		while ((strln=read(fd,buffer,16384))!=0) {
 			write(fdesc,buffer,strln);
 		}
@@ -415,7 +434,8 @@
 		lseek(fd,seekpos,SEEK_SET);
 	}
 	
-	ast_log(LOG_WARNING,"Passing data to channel...\n");
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_4 "Passing data to channel...\n");
 	
 	/* Read back info from server */
 	/* This assumes only one waveform will come back, also LP is unlikely */
@@ -425,15 +445,14 @@
 			n += read(fd,ack+n,3-n);
 		ack[3] = '\0';
 		if (strcmp(ack,"WV\n") == 0) {         /* receive a waveform */
-			ast_log(LOG_WARNING,"Festival WV command");
+			ast_log(LOG_DEBUG,"Festival WV command\n");
 			waveform = socket_receive_file_to_buff(fd,&filesize);
-			send_waveform_to_channel(chan,waveform,filesize);
+			res = send_waveform_to_channel(chan,waveform,filesize,ignoredtmf);
 			free(waveform);
-			res=0;
 			break;
 		}
 		else if (strcmp(ack,"LP\n") == 0) {   /* receive an s-expr */
-			ast_log(LOG_WARNING,"Festival LP command");
+			ast_log(LOG_DEBUG,"Festival LP command\n");
 			waveform = socket_receive_file_to_buff(fd,&filesize);
 			waveform[filesize]='\0';
 			ast_log(LOG_WARNING,"Festival returned LP : %s\n",waveform);
@@ -450,16 +469,31 @@
 
 }
 
+static int festival_exec_bg(struct ast_channel *chan, void *data)
+{
+	festival_exec(chan,data,0);
+}
+
+static int festival_exec_fg(struct ast_channel *chan, void *data)
+{
+	festival_exec(chan,data,1);
+}
+
 int unload_module(void)
 {
+	int res;
 	STANDARD_HANGUP_LOCALUSERS;
-	return ast_unregister_application(app);
+	res = ast_unregister_application(app);
+	res |= ast_unregister_application(app_bg);
+	return res;
 }
 
 int load_module(void)
 {
-	
-	return ast_register_application(app, festival_exec, synopsis, descrip);
+	int res;
+	res = ast_register_application(app, festival_exec_fg, synopsis, descrip);
+	res |= ast_register_application(app_bg, festival_exec_bg, synopsis, descrip_bg);
+	return res;
 }
 
 char *description(void)
