]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
move common say 'spell' function into shared code
authorMichael Jerris <mike@jerris.com>
Sun, 7 Mar 2010 21:26:36 +0000 (21:26 +0000)
committerMichael Jerris <mike@jerris.com>
Sun, 7 Mar 2010 21:26:36 +0000 (21:26 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16931 d0543943-73ff-0310-b7d9-9358b9ac24b2

Makefile.am
src/include/switch_ivr.h
src/mod/say/mod_say_en/mod_say_en.c
src/switch_ivr_play_say.c
src/switch_ivr_say.c [new file with mode: 0644]
w32/Library/FreeSwitchCore.2008.vcproj
w32/Library/FreeSwitchCore.vcproj

index 7d50a55bf7274a2dce3f77b168e57b73344d9b35..b07a65f569439f0fbd0dab3be2b3fa62fb5828ea 100644 (file)
@@ -215,6 +215,7 @@ libfreeswitch_la_SOURCES = \
        src/switch_ivr_originate.c \
        src/switch_ivr_async.c \
        src/switch_ivr_play_say.c \
+       src/switch_ivr_say.c \
        src/switch_ivr_menu.c \
        src/switch_ivr.c \
        src/switch_stun.c \
index f8284f8254539d707631d3d7503fddb5494be378..1e9ad9797fc0481e893a5513cfd5131f8a68aaa9 100644 (file)
@@ -821,6 +821,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session,
 SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name);
 SWITCH_DECLARE(switch_say_gender_t) switch_ivr_get_say_gender_by_name(const char *name);
 SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name);
+SWITCH_DECLARE(switch_status_t) switch_ivr_say_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args);
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data);
 SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session);
 SWITCH_DECLARE(void) switch_process_import(switch_core_session_t *session, switch_channel_t *peer_channel, const char *varname);
index 13f20247b223b008df51a5707944248344c298eb..e8e2b5847732d7015f3528b11a886b66f2be6a1c 100644 (file)
@@ -81,26 +81,6 @@ SWITCH_MODULE_DEFINITION(mod_say_en, mod_say_en_load, NULL, NULL);
                }}                                                                                                                              \
 
 
-static switch_status_t en_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
-{
-       char *p;
-
-       for (p = tosay; p && *p; p++) {
-               int a = tolower((int) *p);
-               if (a >= 48 && a <= 57) {
-                       say_file("digits/%d.wav", a - 48);
-               } else {
-                       if (say_args->type == SST_NAME_SPELLED) {
-                               say_file("ascii/%d.wav", a);
-                       } else if (say_args->type == SST_NAME_PHONETIC) {
-                               say_file("phonetic-ascii/%d.wav", a);
-                       }
-               }
-       }
-
-       return SWITCH_STATUS_SUCCESS;
-}
-
 static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
 {
 
@@ -573,7 +553,7 @@ static switch_status_t en_say(switch_core_session_t *session, char *tosay, switc
                break;
        case SST_NAME_SPELLED:
        case SST_NAME_PHONETIC:
-               say_cb = en_spell;
+               return switch_ivr_say_spell(session, tosay, say_args, args);
                break;
        case SST_CURRENCY:
                say_cb = en_say_money;
index 3d3197f4f4d9f9f1167f5686ed4a0b192b42dcaf..084a536aff7f3827b7431bf5c9e0edde3180bc23 100644 (file)
 
 #include <switch.h>
 
-static char *SAY_METHOD_NAMES[] = {
-       "N/A",
-       "PRONOUNCED",
-       "ITERATED",
-       "COUNTED",
-       NULL
-};
-
-static char *SAY_TYPE_NAMES[] = {
-       "NUMBER",
-       "ITEMS",
-       "PERSONS",
-       "MESSAGES",
-       "CURRENCY",
-       "TIME_MEASUREMENT",
-       "CURRENT_DATE",
-       "CURRENT_TIME",
-       "CURRENT_DATE_TIME",
-       "TELEPHONE_NUMBER",
-       "TELEPHONE_EXTENSION",
-       "URL",
-       "IP_ADDRESS",
-       "EMAIL_ADDRESS",
-       "POSTAL_ADDRESS",
-       "ACCOUNT_NUMBER",
-       "NAME_SPELLED",
-       "NAME_PHONETIC",
-       "SHORT_DATE_TIME",
-       NULL
-};
-
-static char *SAY_GENDER_NAMES[] = {
-       "MASCULINE",
-       "FEMININE",
-       "NEUTER",
-       NULL
-};
-
-SWITCH_DECLARE(switch_say_gender_t) switch_ivr_get_say_gender_by_name(const char *name)
-{
-       int x = 0;
-
-       if (!name) return (switch_say_gender_t)0;
-
-       for (x = 0; SAY_GENDER_NAMES[x]; x++) {
-               if (!strcasecmp(SAY_GENDER_NAMES[x], name)) {
-                       break;
-               }
-       }
-
-       return (switch_say_gender_t) x;
-}
-
-SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name)
-{
-       int x = 0;
-
-       if (!name) return (switch_say_method_t)0;
-
-       for (x = 0; SAY_METHOD_NAMES[x]; x++) {
-               if (!strcasecmp(SAY_METHOD_NAMES[x], name)) {
-                       break;
-               }
-       }
-
-       return (switch_say_method_t) x;
-}
-
-SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name)
-{
-       int x = 0;
-
-       if (!name) return (switch_say_type_t)0;
-
-       for (x = 0; SAY_TYPE_NAMES[x]; x++) {
-               if (!strcasecmp(SAY_TYPE_NAMES[x], name)) {
-                       break;
-               }
-       }
-
-       return (switch_say_type_t) x;
-}
-
 SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro_event(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang,
                                                                                                                switch_input_args_t *args)
 {
diff --git a/src/switch_ivr_say.c b/src/switch_ivr_say.c
new file mode 100644 (file)
index 0000000..cd4ea0d
--- /dev/null
@@ -0,0 +1,162 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthm@freeswitch.org>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthm@freeswitch.org>
+ * Michael Jerris <mike@jerris.com>
+ *
+ * switch_ivr_say.c -- IVR Library (functions to say audio in languages)
+ *
+ */
+
+#include <switch.h>
+
+static char *SAY_METHOD_NAMES[] = {
+       "N/A",
+       "PRONOUNCED",
+       "ITERATED",
+       "COUNTED",
+       NULL
+};
+
+static char *SAY_TYPE_NAMES[] = {
+       "NUMBER",
+       "ITEMS",
+       "PERSONS",
+       "MESSAGES",
+       "CURRENCY",
+       "TIME_MEASUREMENT",
+       "CURRENT_DATE",
+       "CURRENT_TIME",
+       "CURRENT_DATE_TIME",
+       "TELEPHONE_NUMBER",
+       "TELEPHONE_EXTENSION",
+       "URL",
+       "IP_ADDRESS",
+       "EMAIL_ADDRESS",
+       "POSTAL_ADDRESS",
+       "ACCOUNT_NUMBER",
+       "NAME_SPELLED",
+       "NAME_PHONETIC",
+       "SHORT_DATE_TIME",
+       NULL
+};
+
+static char *SAY_GENDER_NAMES[] = {
+       "MASCULINE",
+       "FEMININE",
+       "NEUTER",
+       NULL
+};
+
+SWITCH_DECLARE(switch_say_gender_t) switch_ivr_get_say_gender_by_name(const char *name)
+{
+       int x = 0;
+
+       if (!name) return (switch_say_gender_t)0;
+
+       for (x = 0; SAY_GENDER_NAMES[x]; x++) {
+               if (!strcasecmp(SAY_GENDER_NAMES[x], name)) {
+                       break;
+               }
+       }
+
+       return (switch_say_gender_t) x;
+}
+
+SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name)
+{
+       int x = 0;
+
+       if (!name) return (switch_say_method_t)0;
+
+       for (x = 0; SAY_METHOD_NAMES[x]; x++) {
+               if (!strcasecmp(SAY_METHOD_NAMES[x], name)) {
+                       break;
+               }
+       }
+
+       return (switch_say_method_t) x;
+}
+
+SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name)
+{
+       int x = 0;
+
+       if (!name) return (switch_say_type_t)0;
+
+       for (x = 0; SAY_TYPE_NAMES[x]; x++) {
+               if (!strcasecmp(SAY_TYPE_NAMES[x], name)) {
+                       break;
+               }
+       }
+
+       return (switch_say_type_t) x;
+}
+
+#define say_file(...) {                                                                                                        \
+               char tmp[80];                                                                                                   \
+               switch_status_t tstatus;                                                                                \
+               switch_snprintf(tmp, sizeof(tmp), __VA_ARGS__);                                 \
+               if ((tstatus =                                                                                                  \
+                        switch_ivr_play_file(session, NULL, tmp, args))                        \
+                       != SWITCH_STATUS_SUCCESS){                                                                      \
+                       return tstatus;                                                                                         \
+               }                                                                                                                               \
+               if (!switch_channel_ready(switch_core_session_get_channel(session))) { \
+                       return SWITCH_STATUS_FALSE;                                                                     \
+               }}                                                                                                                              \
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_say_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
+{
+       char *p;
+
+       for (p = tosay; p && *p; p++) {
+               int a = tolower((int) *p);
+               if (a >= '0' && a <= '9') {
+                       say_file("digits/%d.wav", a - '0');
+               } else {
+                       if (say_args->type == SST_NAME_SPELLED) {
+                               say_file("ascii/%d.wav", a);
+                       } else if (say_args->type == SST_NAME_PHONETIC) {
+                               say_file("phonetic-ascii/%d.wav", a);
+                       }
+               }
+       }
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
+ */
index 0e2c671a6474b07418945f33301cc574d03d2171..1db126677ece75a23e499ab23f16d948a69e5659 100644 (file)
                                RelativePath="..\..\src\switch_ivr_play_say.c"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\src\switch_ivr_say.c"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\src\switch_loadable_module.c"\r
                                >\r
index 99abef47177845016ee7e4292b737663ccc6cfe3..11fe44ca244bd40294f955b335ee18fdadee5fe4 100644 (file)
                                RelativePath="..\..\src\switch_ivr_play_say.c"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\src\switch_ivr_say.c"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\src\switch_loadable_module.c"\r
                                >\r