diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index b48bcff800..e8abf5efcf 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -417,13 +417,7 @@ struct switch_say_interface { /*! 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; }; diff --git a/src/include/switch_types.h b/src/include/switch_types.h index ed09ebd731..ac528629e5 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -891,7 +891,6 @@ typedef struct switch_speech_interface switch_speech_interface_t; 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 @@ typedef switch_status_t (*switch_input_callback_function_t)(switch_core_session_ 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); diff --git a/src/mod/formats/mod_sndfile/mod_sndfile.c b/src/mod/formats/mod_sndfile/mod_sndfile.c index 89e0c1ca90..ef79b62a70 100644 --- a/src/mod/formats/mod_sndfile/mod_sndfile.c +++ b/src/mod/formats/mod_sndfile/mod_sndfile.c @@ -135,7 +135,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, char *pat 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; diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index 79e15837f6..409733e7cc 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -33,6 +33,126 @@ static const char modname[] = "mod_say_en"; +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) +{ + char tmp[80] = ""; + + 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); + } + + 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; + } + } + + 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); + } + + if (what && (a || b || c)) { + switch_ivr_play_file(args->session, NULL, what, NULL, args->input_callback, args->buf, args->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 (++x > len) { + ret = NULL; + break; + } + } + + return ret; +} + +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}; + + 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; + } + + 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: + break; + } + +} + static switch_status_t en_say(switch_core_session_t *session, char *tosay, switch_say_type_t type, @@ -41,107 +161,24 @@ static switch_status_t en_say(switch_core_session_t *session, void *buf, uint32_t buflen) { - switch_channel_t *channel; - - assert(session != NULL); - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_say_callback_t say_cb = 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]; - - in = atoi(tosay); - - for(x = 6; x >= 0; x--) { - int num = (int)pow(10, x); - if ((places[x] = in / num)) { - in -= places[x] * num; - } - } - - 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 (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); - } - - if (places[5] || places[4] || places[3]) { - switch_ivr_play_file(session, NULL, "digits/thousand.wav", NULL, input_callback, buf, buflen); - } - - 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); - } - - 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; - } - } - - if (places[0]) { - snprintf(tmp, sizeof(tmp), "digits/%d.wav", places[0]); - switch_ivr_play_file(session, NULL, tmp, NULL, input_callback, buf, buflen); - } - - 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; - } - } + 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; }