mod_say_fr: Update for better french support. Will probably have more stuff from FSCORE-528 to complement this patch

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16933 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Marc Olivier Chouinard 2010-03-08 06:50:27 +00:00
parent 3cab0c7cad
commit e2e669a816
2 changed files with 149 additions and 65 deletions

View File

@ -280,6 +280,7 @@ typedef enum {
SWITCH_TRUE = 1 SWITCH_TRUE = 1
} switch_bool_t; } switch_bool_t;
/* WARNING, Do not forget to update *SAY_METHOD_NAMES[] in src/switch_ivr_play_say.c */
typedef enum { typedef enum {
SSM_NA, SSM_NA,
SSM_PRONOUNCED, SSM_PRONOUNCED,
@ -287,6 +288,7 @@ typedef enum {
SSM_COUNTED SSM_COUNTED
} switch_say_method_t; } switch_say_method_t;
/* WARNING, Do not forget to update *SAY_TYPE_NAMES[] in src/switch_ivr_play_say.c */
typedef enum { typedef enum {
SST_NUMBER, SST_NUMBER,
SST_ITEMS, SST_ITEMS,

View File

@ -39,6 +39,7 @@
* *
* Anthony Minessale II <anthm@freeswitch.org> * Anthony Minessale II <anthm@freeswitch.org>
* Michael B. Murdock <mike@mmurdock.org> * Michael B. Murdock <mike@mmurdock.org>
* Marc O. Chouinard <mochouinard@moctel.com>
* *
* mod_say_fr.c -- Say for french * mod_say_fr.c -- Say for french
* *
@ -66,7 +67,6 @@ SWITCH_MODULE_DEFINITION(mod_say_fr, mod_say_fr_load, NULL, NULL);
say_args->method = smeth; say_args->type = stype; \ say_args->method = smeth; say_args->type = stype; \
} \ } \
#define say_file(...) { \ #define say_file(...) { \
char tmp[80]; \ char tmp[80]; \
switch_status_t tstatus; \ switch_status_t tstatus; \
@ -101,28 +101,55 @@ static switch_status_t fr_spell(switch_core_session_t *session, char *tosay, swi
return SWITCH_STATUS_SUCCESS; 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) static switch_status_t play_group(switch_say_args_t *say_args, int a, int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
{ {
int ftdNumber = 0;
int itd = (b * 10) + c;
if (a) { /* Force full 2 digit playback */
if (itd <= 19)
ftdNumber = 1;
switch (itd) {
case 21:
case 31:
ftdNumber = 1;
}
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c); */
if (a && a !=0) {
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c);*/
if (a != 1)
say_file("digits/%d.wav", a); say_file("digits/%d.wav", a);
say_file("digits/hundred.wav"); say_file("digits/hundred.wav");
} }
if (b) { if (b && ftdNumber == 0) {
if (b > 1) { /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c);*/
say_file("digits/%d0.wav", b); if (c == 0) {
if (say_args->method == SSM_COUNTED) {
say_file("digits/h-%d%d.wav", b, c);
} else { } else {
say_file("digits/%d%d.wav", b, c); say_file("digits/%d%d.wav", b, c);
c = 0; }
} else {
say_file("digits/%d0.wav", b);
} }
} }
if (c) { if (c || (ftdNumber == 1 && (a || b || c))) {
if (method == SSM_COUNTED) { /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c);*/
say_file("digits/h-%d.wav", c); int fVal = c;
if (ftdNumber == 1)
fVal = itd;
if (say_args->method == SSM_COUNTED) {
say_file("digits/h-%d.wav", fVal);
} else { } else {
say_file("digits/%d.wav", c); if (b != 1 && c == 1 && say_args->gender == SSG_FEMININE) {
say_file("digits/%d_f.wav", fVal);
} else {
say_file("digits/%d.wav", fVal);
}
} }
} }
@ -161,7 +188,7 @@ static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
char *p = in, *q = out; char *p = in, *q = out;
char *ret = out; char *ret = out;
switch_size_t x = 0; switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
for (; p && *p; p++) { for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p; *q++ = *p;
@ -202,13 +229,13 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session, char
switch (say_args->method) { switch (say_args->method) {
case SSM_COUNTED: case SSM_COUNTED:
case SSM_PRONOUNCED: case SSM_PRONOUNCED:
if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) { if ((status = play_group(say_args, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) { if ((status = play_group(say_args, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
if ((status = play_group(say_args->method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) { if ((status = play_group(say_args, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
break; break;
@ -216,9 +243,13 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session, char
{ {
char *p; char *p;
for (p = tosay; p && *p; p++) { for (p = tosay; p && *p; p++) {
if (*p == '1' && say_args->gender == SSG_FEMININE) {
say_file("digits/%c_f.wav", *p);
} else {
say_file("digits/%c.wav", *p); say_file("digits/%c.wav", *p);
} }
} }
}
break; break;
default: default:
break; break;
@ -271,9 +302,11 @@ static switch_status_t fr_ip(switch_core_session_t *session, char *tosay, switch
static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{ {
int32_t t; int32_t t;
switch_time_t target = 0; switch_time_t target = 0, target_now = 0;
switch_time_exp_t tm; switch_time_exp_t tm, tm_now;
uint8_t say_date = 0, say_time = 0; uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *tz = switch_channel_get_variable(channel, "timezone");
if (say_args->type == SST_TIME_MEASUREMENT) { if (say_args->type == SST_TIME_MEASUREMENT) {
int64_t hours = 0; int64_t hours = 0;
@ -299,7 +332,7 @@ static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay,
} }
} }
} else { } else {
if ((seconds = atoi(tosay)) <= 0) { if ((seconds = atol(tosay)) <= 0) {
seconds = (int64_t) switch_epoch_time_now(NULL); seconds = (int64_t) switch_epoch_time_now(NULL);
} }
@ -316,51 +349,59 @@ static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay,
} }
} }
say_args->gender = SSG_FEMININE;
if (hours) { if (hours) {
say_num(hours, SSM_PRONOUNCED); say_num(hours, SSM_PRONOUNCED);
if (hours == 1) {
say_file("time/hour.wav"); say_file("time/hour.wav");
} else { } else {
say_file("time/hours.wav"); /* TODO MINUIT */
}
} else {
say_file("digits/0.wav"); say_file("digits/0.wav");
say_file("time/hours.wav"); say_file("time/hour.wav");
} }
if (minutes) { if (minutes) {
say_num(minutes, SSM_PRONOUNCED); say_num(minutes, SSM_PRONOUNCED);
if (minutes == 1) {
say_file("time/minute.wav"); say_file("time/minute.wav");
} else { } else {
say_file("time/minutes.wav"); /* TODO Aucune idee quoi faire jouer icit */
}
} else {
say_file("digits/0.wav"); say_file("digits/0.wav");
say_file("time/minutes.wav"); say_file("time/minute.wav");
} }
if (seconds) { if (seconds) {
say_num(seconds, SSM_PRONOUNCED); say_num(seconds, SSM_PRONOUNCED);
if (seconds == 1) {
say_file("time/second.wav"); say_file("time/second.wav");
} else { } else {
say_file("time/seconds.wav"); /* TODO Aucune idee quoi faire jouer icit */
}
} else {
say_file("digits/0.wav"); say_file("digits/0.wav");
say_file("time/seconds.wav"); say_file("time/second.wav");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if ((t = atoi(tosay)) > 0) { if ((t = atol(tosay)) > 0) {
target = switch_time_make(t, 0); target = switch_time_make(t, 0);
target_now = switch_micro_time_now();
} else { } else {
target = switch_micro_time_now(); target = switch_micro_time_now();
target_now = switch_micro_time_now();
} }
if (tz) {
int check = atoi(tz);
if (check) {
switch_time_exp_tz(&tm, target, check);
switch_time_exp_tz(&tm_now, target_now, check);
} else {
switch_time_exp_tz_name(tz, &tm, target);
switch_time_exp_tz_name(tz, &tm_now, target_now);
}
} else {
switch_time_exp_lt(&tm, target); switch_time_exp_lt(&tm, target);
switch_time_exp_lt(&tm_now, target_now);
}
switch (say_args->type) { switch (say_args->type) {
case SST_CURRENT_DATE_TIME: case SST_CURRENT_DATE_TIME:
@ -372,42 +413,82 @@ static switch_status_t fr_say_time(switch_core_session_t *session, char *tosay,
case SST_CURRENT_TIME: case SST_CURRENT_TIME:
say_time = 1; say_time = 1;
break; break;
case SST_SHORT_DATE_TIME:
say_time = 1;
if (tm.tm_year != tm_now.tm_year) {
say_date = 1;
break;
}
if (tm.tm_yday == tm_now.tm_yday) {
say_today = 1;
break;
}
if (tm.tm_yday == tm_now.tm_yday - 1) {
say_yesterday = 1;
break;
}
if (tm.tm_yday >= tm_now.tm_yday - 5) {
say_dow = 1;
break;
}
if (tm.tm_mon != tm_now.tm_mon) {
say_month = say_day = say_dow = 1;
break;
}
say_month = say_day = say_dow = 1;
break;
default: default:
break; break;
} }
if (say_date) { if (say_today) {
say_file("time/today.wav");
}
if (say_yesterday) {
say_file("time/yesterday.wav");
}
if (say_dow) {
say_file("time/day-%d.wav", tm.tm_wday); say_file("time/day-%d.wav", tm.tm_wday);
say_file("time/mon-%d.wav", tm.tm_mon); }
if (say_date) {
say_year = say_month = say_day = say_dow = 1;
say_today = say_yesterday = 0;
}
if (say_day) {
if (tm.tm_mday == 1) { /* 1 er Janvier,... 2 feb, 23 dec... */
say_args->gender = SSG_MASCULINE;
say_num(tm.tm_mday, SSM_COUNTED); say_num(tm.tm_mday, SSM_COUNTED);
} else {
say_args->gender = SSG_FEMININE;
say_num(tm.tm_mday, SSM_PRONOUNCED);
}
}
if (say_month) {
say_file("time/mon-%d.wav", tm.tm_mon);
}
if (say_year) {
say_args->gender = SSG_MASCULINE;
say_num(tm.tm_year + 1900, SSM_PRONOUNCED); say_num(tm.tm_year + 1900, SSM_PRONOUNCED);
} }
if (say_time) { if (say_time) {
int32_t hour = tm.tm_hour, pm = 0; if (say_date || say_today || say_yesterday || say_dow) {
say_file("time/at.wav");
}
say_args->gender = SSG_FEMININE;
say_num(tm.tm_hour, SSM_PRONOUNCED);
if (hour > 12) { say_file("time/hour.wav");
hour -= 12;
pm = 1; if (tm.tm_min) {
} else if (hour == 12) { say_num(tm.tm_min, SSM_PRONOUNCED);
pm = 1;
} else if (hour == 0) {
hour = 12;
pm = 0;
} }
say_num(hour, SSM_PRONOUNCED);
if (tm.tm_min > 9) {
say_num(tm.tm_min, SSM_PRONOUNCED);
} else if (tm.tm_min) {
say_file("time/oh.wav");
say_num(tm.tm_min, SSM_PRONOUNCED);
} else {
say_file("time/oclock.wav");
}
say_file("time/%s.wav", pm ? "p-m" : "a-m");
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -490,6 +571,7 @@ static switch_status_t fr_say(switch_core_session_t *session, char *tosay, switc
case SST_CURRENT_DATE: case SST_CURRENT_DATE:
case SST_CURRENT_TIME: case SST_CURRENT_TIME:
case SST_CURRENT_DATE_TIME: case SST_CURRENT_DATE_TIME:
case SST_SHORT_DATE_TIME:
say_cb = fr_say_time; say_cb = fr_say_time;
break; break;
case SST_IP_ADDRESS: case SST_IP_ADDRESS: