[Freeswitch-trunk] [commit] r3791 - in freeswitch/trunk/src: include mod/formats/mod_sndfile mod/say/mod_say_en
Freeswitch SVN
anthm at freeswitch.org
Thu Dec 21 21:13:57 EST 2006
Author: anthm
Date: Thu Dec 21 21:13:56 2006
New Revision: 3791
Modified:
freeswitch/trunk/src/include/switch_module_interfaces.h
freeswitch/trunk/src/include/switch_types.h
freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c
freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c
Log:
refactor say api to try and develop a good working example template
Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h (original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h Thu Dec 21 21:13:56 2006
@@ -417,13 +417,7 @@
/*! the name of the interface */
const char *interface_name;
/*! function to pass down to the module */
- switch_status_t (*say_function)(switch_core_session_t *session,
- char *tosay,
- switch_say_type_t type,
- switch_say_method_t method,
- switch_input_callback_function_t dtmf_callback,
- void *buf,
- uint32_t buflen);
+ switch_say_callback_t say_function;
const struct switch_say_interface *next;
};
Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h (original)
+++ freeswitch/trunk/src/include/switch_types.h Thu Dec 21 21:13:56 2006
@@ -891,7 +891,6 @@
typedef struct switch_asr_interface switch_asr_interface_t;
typedef struct switch_directory_interface switch_directory_interface_t;
typedef struct switch_chat_interface switch_chat_interface_t;
-typedef struct switch_say_interface switch_say_interface_t;
typedef struct switch_core_port_allocator switch_core_port_allocator_t;
typedef struct switch_media_bug switch_media_bug_t;
typedef void (*switch_media_bug_callback_t)(switch_media_bug_t *, void *, switch_abc_type_t);
@@ -917,6 +916,14 @@
switch_input_type_t input_type,
void *buf,
unsigned int buflen);
+typedef struct switch_say_interface switch_say_interface_t;
+typedef switch_status_t (*switch_say_callback_t)(switch_core_session_t *session,
+ char *tosay,
+ switch_say_type_t type,
+ switch_say_method_t method,
+ switch_input_callback_function_t input_callback,
+ void *buf,
+ uint32_t buflen);
typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames);
typedef switch_status_t (*switch_module_load_t) (switch_loadable_module_interface_t **, char *);
typedef switch_status_t (*switch_module_reload_t) (void);
Modified: freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c (original)
+++ freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c Thu Dec 21 21:13:56 2006
@@ -135,7 +135,7 @@
return SWITCH_STATUS_GENERR;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
handle->samples = (unsigned int) context->sfinfo.frames;
handle->samplerate = context->sfinfo.samplerate;
handle->channels = (uint8_t)context->sfinfo.channels;
Modified: freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c
==============================================================================
--- freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c (original)
+++ freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c Thu Dec 21 21:13:56 2006
@@ -33,115 +33,152 @@
static const char modname[] = "mod_say_en";
-static switch_status_t en_say(switch_core_session_t *session,
- char *tosay,
- switch_say_type_t type,
- switch_say_method_t method,
- switch_input_callback_function_t input_callback,
- void *buf,
- uint32_t buflen)
+typedef struct {
+ switch_core_session_t *session;
+ switch_input_callback_function_t input_callback;
+ void *buf;
+ uint32_t buflen;
+} common_args_t;
+
+static void play_group(int a, int b, int c, char *what, common_args_t *args)
{
- switch_channel_t *channel;
+ char tmp[80] = "";
- assert(session != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
-
- switch(type) {
- case SST_NUMBER:
- case SST_ITEMS:
- case SST_PERSONS:
- case SST_MESSAGES:
- {
- int in;
- int x, places[7] = {0};
- char tmp[25];
+ if (a) {
+ snprintf(tmp, sizeof(tmp), "digits/%d.wav", a);
+ switch_ivr_play_file(args->session, NULL, tmp, NULL, args->input_callback, args->buf, args->buflen);
+ switch_ivr_play_file(args->session, NULL, "digits/hundred.wav", NULL, args->input_callback, args->buf, args->buflen);
+ }
- in = atoi(tosay);
+ if (b) {
+ if (b > 1) {
+ snprintf(tmp, sizeof(tmp), "digits/%d0.wav", b);
+ switch_ivr_play_file(args->session, NULL, tmp, NULL, args->input_callback, args->buf, args->buflen);
+ } else {
+ snprintf(tmp, sizeof(tmp), "digits/%d%d.wav", b, c);
+ switch_ivr_play_file(args->session, NULL, tmp, NULL, args->input_callback, args->buf, args->buflen);
+ c = 0;
+ }
+ }
- for(x = 6; x >= 0; x--) {
- int num = (int)pow(10, x);
- if ((places[x] = in / num)) {
- in -= places[x] * num;
- }
- }
+ if (c) {
+ snprintf(tmp, sizeof(tmp), "digits/%d.wav", c);
+ switch_ivr_play_file(args->session, NULL, tmp, NULL, args->input_callback, args->buf, args->buflen);
+ }
- switch (method) {
- case SSM_PRONOUNCED:
- if (places[6]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[6]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- switch_ivr_play_file(session, NULL, "digits/million.wav", NULL, input_callback, buf, buflen);
- }
+ if (what && (a || b || c)) {
+ switch_ivr_play_file(args->session, NULL, what, NULL, args->input_callback, args->buf, args->buflen);
+ }
- if (places[5]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[5]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- switch_ivr_play_file(session, NULL, "digits/hundred.wav", NULL, input_callback, buf, buflen);
- }
-
- if (places[4]) {
- if (places[4] > 1) {
- snprintf(tmp, sizeof(tmp), "digits/%d0.wav", places[4]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- } else {
- snprintf(tmp, sizeof(tmp), "digits/%d%d.wav", places[4], places[3]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- places[3] = 0;
- }
- }
-
- if (places[3]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[3]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- }
+}
+
+static char *strip_commas(char *in, char *out, switch_size_t len)
+{
+ char *p = in, *q = out;
+ char *ret = out;
+ int x = 0;
+
+ for(;p && *p; p++) {
+ if ((*p > 47 && *p < 58)) {
+ *q++ = *p;
+ } else if (*p != ',') {
+ ret = NULL;
+ break;
+ }
- if (places[5] || places[4] || places[3]) {
- switch_ivr_play_file(session, NULL, "digits/thousand.wav", NULL, input_callback, buf, buflen);
- }
+ if (++x > len) {
+ ret = NULL;
+ break;
+ }
+ }
- if (places[2]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[2]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- switch_ivr_play_file(session, NULL, "digits/hundred.wav", NULL, input_callback, buf, buflen);
- }
+ return ret;
+}
- if (places[1]) {
- if (places[1] > 1) {
- snprintf(tmp, sizeof(tmp), "digits/%d0.wav", places[1]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- } else {
- snprintf(tmp, sizeof(tmp), "digits/%d%d.wav", places[1], places[0]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- places[0] = 0;
- }
- }
+static switch_status_t en_say_general_count(switch_core_session_t *session,
+ char *tosay,
+ switch_say_type_t type,
+ switch_say_method_t method,
+ switch_input_callback_function_t input_callback,
+ void *buf,
+ uint32_t buflen)
+{
+ switch_channel_t *channel;
+ int in;
+ int x = 0, places[9] = {0};
+ char tmp[80] = "";
+ char sbuf[13] = "";
+ common_args_t args = {0};
- if (places[0]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[0]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- }
+ assert(session != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ args.session = session;
+ args.input_callback = input_callback;
+ args.buf = buf;
+ args.buflen = buflen;
+
+ if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
+ return SWITCH_STATUS_GENERR;
+ }
- break;
- case SSM_ITERATED:
- for(x = 7; x >= 0; x--) {
- if (places[x]) {
- snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[x]);
- switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
- }
- }
- break;
- default:
- break;
+ in = atoi(tosay);
+
+ for(x = 8; x >= 0; x--) {
+ int num = (int)pow(10, x);
+ if ((places[x] = in / num)) {
+ in -= places[x] * num;
+ }
+ }
+
+ switch (method) {
+ case SSM_PRONOUNCED:
+ play_group(places[8], places[7], places[6], "digits/million.wav", &args);
+ play_group(places[5], places[4], places[3], "digits/thousand.wav", &args);
+ play_group(places[2], places[1], places[0], NULL, &args);
+ break;
+ case SSM_ITERATED:
+ for(x = 8; x >= 0; x--) {
+ if (places[x]) {
+ snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[x]);
+ switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen);
}
}
break;
default:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Finish ME!\n");
break;
}
+}
+static switch_status_t en_say(switch_core_session_t *session,
+ char *tosay,
+ switch_say_type_t type,
+ switch_say_method_t method,
+ switch_input_callback_function_t input_callback,
+ void *buf,
+ uint32_t buflen)
+{
+
+ switch_say_callback_t say_cb = NULL;
+
+ switch(type) {
+ case SST_NUMBER:
+ case SST_ITEMS:
+ case SST_PERSONS:
+ case SST_MESSAGES:
+ say_cb = en_say_general_count;
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Finish ME!\n");
+ break;
+ }
+
+ if (say_cb) {
+ say_cb(session, tosay, type, method, input_callback, buf, buflen);
+ }
return SWITCH_STATUS_SUCCESS;
}
More information about the Freeswitch-trunk
mailing list