[asterisk-commits] file: branch file/speech-agi r50224 - in /team/file/speech-agi: include/aster...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 9 18:45:54 MST 2007


Author: file
Date: Tue Jan  9 19:45:53 2007
New Revision: 50224

URL: http://svn.digium.com/view/asterisk?view=rev&rev=50224
Log:
Add AGI Speech commands, everything except for recognition.

Modified:
    team/file/speech-agi/include/asterisk/agi.h
    team/file/speech-agi/res/res_agi.c

Modified: team/file/speech-agi/include/asterisk/agi.h
URL: http://svn.digium.com/view/asterisk/team/file/speech-agi/include/asterisk/agi.h?view=diff&rev=50224&r1=50223&r2=50224
==============================================================================
--- team/file/speech-agi/include/asterisk/agi.h (original)
+++ team/file/speech-agi/include/asterisk/agi.h Tue Jan  9 19:45:53 2007
@@ -28,9 +28,10 @@
 #endif
 
 typedef struct agi_state {
-	int fd;		/* FD for general output */
-	int audio;	/* FD for audio output */
-	int ctrl;	/* FD for input control */
+	int fd;                    /* FD for general output */
+	int audio;	           /* FD for audio output */
+	int ctrl;	           /* FD for input control */
+	struct ast_speech *speech; /* Speech structure */
 } AGI;
 
 typedef struct agi_command {

Modified: team/file/speech-agi/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/team/file/speech-agi/res/res_agi.c?view=diff&rev=50224&r1=50223&r2=50224
==============================================================================
--- team/file/speech-agi/res/res_agi.c (original)
+++ team/file/speech-agi/res/res_agi.c Tue Jan  9 19:45:53 2007
@@ -64,6 +64,7 @@
 #include "asterisk/lock.h"
 #include "asterisk/strings.h"
 #include "asterisk/agi.h"
+#include "asterisk/speech.h"
 
 #define MAX_ARGS 128
 #define MAX_COMMANDS 128
@@ -1309,6 +1310,135 @@
 	return RESULT_SUCCESS;
 }
 
+static int handle_speechcreate(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	/* If a structure already exists, return an error */
+	if (agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	if ((agi->speech = ast_speech_new(argv[2], AST_FORMAT_SLINEAR)))
+		fdprintf(agi->fd, "200 result=1\n");
+	else
+		fdprintf(agi->fd, "200 result=0\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechset(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	/* Check for minimum arguments */
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+
+	/* Check to make sure speech structure exists */
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	ast_speech_change(agi->speech, argv[2], argv[3]);
+	fdprintf(agi->fd, "200 result=1\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechdestroy(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (agi->speech) {
+		ast_speech_destroy(agi->speech);
+		agi->speech = NULL;
+		fdprintf(agi->fd, "200 result=1\n");
+	} else {
+		fdprintf(agi->fd, "200 result=0\n");
+	}
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechloadgrammar(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (argc != 5)
+		return RESULT_SHOWUSAGE;
+
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	if (ast_speech_grammar_load(agi->speech, argv[3], argv[4]))
+		fdprintf(agi->fd, "200 result=0\n");
+	else
+		fdprintf(agi->fd, "200 result=1\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechunloadgrammar(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (argc != 4)
+		return RESULT_SHOWUSAGE;
+
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	if (ast_speech_grammar_unload(agi->speech, argv[3]))
+		fdprintf(agi->fd, "200 result=0\n");
+	else
+		fdprintf(agi->fd, "200 result=1\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechactivategrammar(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (argc != 4)
+		return RESULT_SHOWUSAGE;
+
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	if (ast_speech_grammar_activate(agi->speech, argv[3]))
+		fdprintf(agi->fd, "200 result=0\n");
+	else
+		fdprintf(agi->fd, "200 result=1\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechdeactivategrammar(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (argc != 4)
+		return RESULT_SHOWUSAGE;
+
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	if (ast_speech_grammar_deactivate(agi->speech, argv[3]))
+		fdprintf(agi->fd, "200 result=0\n");
+	else
+		fdprintf(agi->fd, "200 result=1\n");
+
+	return RESULT_SUCCESS;
+}
+
+static int handle_speechrecognize(struct ast_channel *chan, AGI *agi, int argc, char **argv)
+{
+	if (!agi->speech) {
+		fdprintf(agi->fd, "200 result=0\n");
+		return RESULT_SUCCESS;
+	}
+
+	return RESULT_SUCCESS;
+}
+
 static char debug_usage[] = 
 "Usage: agi debug\n"
 "       Enables dumping of AGI transactions for debugging purposes\n";
@@ -1606,6 +1736,37 @@
 static char usage_noop[] =
 " Usage: NoOp\n"
 "	Does nothing.\n";
+
+static char usage_speechcreate[] =
+" Usage: SPEECH CREATE <engine>\n"
+"       Create a speech object to be used by the other Speech AGI commands.\n";
+
+static char usage_speechset[] =
+" Usage: SPEECH SET <name> <value>\n"
+"       Set an engine-specific setting.\n";
+
+static char usage_speechdestroy[] =
+" Usage: SPEECH DESTROY\n"
+"       Destroy the speech object created by SPEECH CREATE.\n";
+
+static char usage_speechloadgrammar[] =
+" Usage: SPEECH LOAD GRAMMAR <grammar name> <path to grammar>\n"
+"       Loads the specified grammar as the specified name.\n";
+
+static char usage_speechunloadgrammar[] =
+" Usage: SPEECH UNLOAD GRAMMAR <grammar name>\n"
+"       Unloads the specified grammar.\n";
+
+static char usage_speechactivategrammar[] =
+" Usage: SPEECH ACTIVATE GRAMMAR <grammar name>\n"
+"       Activates the specified grammar on the speech object.\n";
+
+static char usage_speechdeactivategrammar[] =
+" Usage: SPEECH DEACTIVATE GRAMMAR <grammar name>\n"
+"       Deactivates the specified grammar on the speech object.\n";
+
+static char usage_speechrecognize[] =
+" Usage: SPEECH RECOGNIZE\n";
 
 static agi_command commands[MAX_COMMANDS] = {
 	{ { "answer", NULL }, handle_answer, "Answer channel", usage_answer },
@@ -1645,6 +1806,15 @@
 	{ { "tdd", "mode", NULL }, handle_tddmode, "Toggles TDD mode (for the deaf)", usage_tddmode },
 	{ { "verbose", NULL }, handle_verbose, "Logs a message to the asterisk verbose log", usage_verbose },
 	{ { "wait", "for", "digit", NULL }, handle_waitfordigit, "Waits for a digit to be pressed", usage_waitfordigit },
+	/* Speech commands */
+	{ { "speech", "create", NULL }, handle_speechcreate, "Creates a speech object", usage_speechcreate },
+	{ { "speech", "set", NULL }, handle_speechset, "Sets a speech engine setting", usage_speechset },
+	{ { "speech", "destroy", NULL }, handle_speechdestroy, "Destroys a speech object", usage_speechdestroy },
+	{ { "speech", "load", "grammar", NULL }, handle_speechloadgrammar, "Loads a grammar", usage_speechloadgrammar },
+	{ { "speech", "unload", "grammar", NULL }, handle_speechunloadgrammar, "Unloads a grammar", usage_speechunloadgrammar },
+	{ { "speech", "activate", "grammar", NULL }, handle_speechactivategrammar, "Activates a grammar", usage_speechactivategrammar },
+	{ { "speech", "deactivate", "grammar", NULL }, handle_speechdeactivategrammar, "Deactivates a grammar", usage_speechdeactivategrammar },
+	{ { "speech", "recognize", NULL }, handle_speechrecognize, "Recognizes speech", usage_speechrecognize },
 };
 
 static int help_workhorse(int fd, char *match[])



More information about the asterisk-commits mailing list