[asterisk-commits] murf: branch murf/sayphn r56954 -
/team/murf/sayphn/apps/app_sayphonenumber.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Feb 26 17:18:10 MST 2007
Author: murf
Date: Mon Feb 26 18:18:10 2007
New Revision: 56954
URL: http://svn.digium.com/view/asterisk?view=rev&rev=56954
Log:
Added an experimental app, app_sayphonenumber.c, to see if reading a phone number can sound more 'natural'. Hah, all I can say is, it'll be a little bit more work. Most of the effort is in the sounds. I need to upgrade the app, to allow other options for specifying where the pauses should be, without specifying them in the number itself.
Added:
team/murf/sayphn/apps/app_sayphonenumber.c (with props)
Added: team/murf/sayphn/apps/app_sayphonenumber.c
URL: http://svn.digium.com/view/asterisk/team/murf/sayphn/apps/app_sayphonenumber.c?view=auto&rev=56954
==============================================================================
--- team/murf/sayphn/apps/app_sayphonenumber.c (added)
+++ team/murf/sayphn/apps/app_sayphonenumber.c Mon Feb 26 18:18:10 2007
@@ -1,0 +1,136 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (c) 2007 Digium, Inc.
+ *
+ * Steve Murphy <murf at digium.com>
+ *
+ * This code is released by the author with no restrictions on usage.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ */
+
+/*! \file
+ *
+ * \brief SayPhoneNumber application
+ *
+ * \author Steve Murphy <murf at digium.com>
+ *
+ * \ingroup applications
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/say.h"
+#include "asterisk/app.h"
+
+static char *app_sayphonenumber = "SayPhoneNumber";
+
+static char *sayphonenumber_synopsis = "Says a phone number in natural, quick way";
+
+static char *sayphonenumber_descrip =
+"SayPhoneNumber(number)\n"
+" number: a phone number to speak. Non-numeric characters will be substituted with pause.\n";
+
+
+static int sayphone(struct ast_channel *chan, char *num)
+{
+ char *t = num;
+ char digitstr[20];
+ int res;
+ if (!t || *t == 0)
+ return 0;
+ while (!isdigit(*t)) /* no use pausing on leading non-numbers */
+ t++;
+
+ while (*t) {
+ if (isdigit(*t)) {
+ if (*(t+1) && isdigit(*(t+1))) {
+ strcpy(digitstr,"digits2/X"); /* It's all in the sounds-- the f sounds are brief, with no silence fore or aft. */
+ digitstr[8] = *t;
+ digitstr[9] = 'f';
+ digitstr[10] = 0;
+ } else {
+ strcpy(digitstr,"digits2/X"); /* the non-f sounds are slightly prolonged or slower; Seems that humans really don't speak much faster than normal... */
+ digitstr[8] = *t;
+ digitstr[9] = 0;
+ }
+ res = ast_streamfile(chan,digitstr,chan->language);
+ if (!res)
+ res = ast_waitstream_full(chan, "", -1, -1);
+ ast_stopstream(chan);
+ }
+ t++;
+ }
+ return 0;
+}
+
+static int sayphonenumber_exec(struct ast_channel *chan, void *data)
+{
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(p1);
+ );
+ char *parse;
+ int res = 0;
+ struct ast_module_user *u;
+
+ if (!data)
+ return 0;
+
+ parse = ast_strdupa(data);
+
+ u = ast_module_user_add(chan);
+
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (chan->_state != AST_STATE_UP)
+ res = ast_answer(chan);
+ ast_log(LOG_WARNING,"say phone number %s\n", (char*)data);
+ if (!res)
+ res = sayphone(chan, data);
+
+ ast_module_user_remove(u);
+
+ return res;
+}
+
+static int unload_module(void)
+{
+ int res;
+
+ res = ast_unregister_application(app_sayphonenumber);
+
+ ast_module_user_hangup_all();
+
+ return res;
+}
+
+static int load_module(void)
+{
+ int res;
+
+ res = ast_register_application(app_sayphonenumber, sayphonenumber_exec, sayphonenumber_synopsis, sayphonenumber_descrip);
+
+ return res;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say phone number");
Propchange: team/murf/sayphn/apps/app_sayphonenumber.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/murf/sayphn/apps/app_sayphonenumber.c
------------------------------------------------------------------------------
svn:keywords = Author Id Date Revision
Propchange: team/murf/sayphn/apps/app_sayphonenumber.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list