2007-10-17 19:52:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007, Anthony Minessale II
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the original author; nor the names of any contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-10-17 19:52:43 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-10-17 19:52:43 +00:00
|
|
|
* Michael B. Murdock <mike@mmurdock.org>
|
2010-03-08 06:50:27 +00:00
|
|
|
* Marc O. Chouinard <mochouinard@moctel.com>
|
2007-10-17 19:52:43 +00:00
|
|
|
*
|
2010-03-07 19:34:05 +00:00
|
|
|
* mod_say_fr.c -- Say for french
|
2007-10-17 19:52:43 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2007-10-17 20:17:00 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_say_fr_load);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_say_fr, mod_say_fr_load, NULL, NULL);
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
#define say_num(num, meth) { \
|
|
|
|
char tmp[80]; \
|
|
|
|
switch_status_t tstatus; \
|
|
|
|
switch_say_method_t smeth = say_args->method; \
|
|
|
|
switch_say_type_t stype = say_args->type; \
|
|
|
|
say_args->type = SST_ITEMS; say_args->method = meth; \
|
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num); \
|
|
|
|
if ((tstatus = \
|
|
|
|
fr_say_general_count(session, tmp, say_args, args)) \
|
|
|
|
!= SWITCH_STATUS_SUCCESS) { \
|
|
|
|
return tstatus; \
|
|
|
|
} \
|
|
|
|
say_args->method = smeth; say_args->type = stype; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#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; \
|
|
|
|
}} \
|
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t fr_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
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 {
|
2010-03-07 19:34:05 +00:00
|
|
|
if (say_args->type == SST_NAME_SPELLED) {
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("ascii/%d.wav", a);
|
2010-03-07 19:34:05 +00:00
|
|
|
} else if (say_args->type == SST_NAME_PHONETIC) {
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("phonetic-ascii/%d.wav", a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
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)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
2010-03-08 06:50:27 +00:00
|
|
|
int ftdNumber = 0;
|
|
|
|
int itd = (b * 10) + c;
|
|
|
|
|
|
|
|
/* 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); */
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
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);
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/hundred.wav");
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
if (b && ftdNumber == 0) {
|
|
|
|
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c);*/
|
|
|
|
if (c == 0) {
|
|
|
|
if (say_args->method == SSM_COUNTED) {
|
|
|
|
say_file("digits/h-%d%d.wav", b, c);
|
|
|
|
} else {
|
|
|
|
say_file("digits/%d%d.wav", b, c);
|
|
|
|
}
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("digits/%d0.wav", b);
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
if (c || (ftdNumber == 1 && (a || b || c))) {
|
|
|
|
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "a=%d b=[%d] c=%d\n",a, b,c);*/
|
|
|
|
int fVal = c;
|
|
|
|
if (ftdNumber == 1)
|
|
|
|
fVal = itd;
|
|
|
|
|
|
|
|
if (say_args->method == SSM_COUNTED) {
|
|
|
|
say_file("digits/h-%d.wav", fVal);
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
if (b != 1 && c == 1 && say_args->gender == SSG_FEMININE) {
|
|
|
|
say_file("digits/%d_f.wav", fVal);
|
|
|
|
} else {
|
|
|
|
say_file("digits/%d.wav", fVal);
|
|
|
|
}
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what && (a || b || c)) {
|
|
|
|
say_file(what);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *strip_commas(char *in, char *out, switch_size_t len)
|
|
|
|
{
|
|
|
|
char *p = in, *q = out;
|
|
|
|
char *ret = out;
|
|
|
|
switch_size_t 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 char *strip_nonnumerics(char *in, char *out, switch_size_t len)
|
|
|
|
{
|
|
|
|
char *p = in, *q = out;
|
|
|
|
char *ret = out;
|
|
|
|
switch_size_t x = 0;
|
2010-03-08 06:50:27 +00:00
|
|
|
/* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
|
2007-10-17 19:52:43 +00:00
|
|
|
for (; p && *p; p++) {
|
|
|
|
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
|
|
|
|
*q++ = *p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++x > len) {
|
|
|
|
ret = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
static switch_status_t fr_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
int in;
|
|
|
|
int x = 0;
|
|
|
|
int places[9] = { 0 };
|
|
|
|
char sbuf[13] = "";
|
|
|
|
switch_status_t status;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (in != 0) {
|
|
|
|
for (x = 8; x >= 0; x--) {
|
|
|
|
int num = (int) pow(10, x);
|
2008-05-27 04:54:52 +00:00
|
|
|
if ((places[(uint32_t) x] = in / num)) {
|
|
|
|
in -= places[(uint32_t) x] * num;
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
switch (say_args->method) {
|
2007-10-17 19:52:43 +00:00
|
|
|
case SSM_COUNTED:
|
|
|
|
case SSM_PRONOUNCED:
|
2010-03-08 06:50:27 +00:00
|
|
|
if ((status = play_group(say_args, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
|
2007-10-17 19:52:43 +00:00
|
|
|
return status;
|
|
|
|
}
|
2010-03-08 06:50:27 +00:00
|
|
|
if ((status = play_group(say_args, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
|
2007-10-17 19:52:43 +00:00
|
|
|
return status;
|
|
|
|
}
|
2010-03-08 06:50:27 +00:00
|
|
|
if ((status = play_group(say_args, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
|
2007-10-17 19:52:43 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSM_ITERATED:
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
for (p = tosay; p && *p; p++) {
|
2010-03-08 06:50:27 +00:00
|
|
|
if (*p == '1' && say_args->gender == SSG_FEMININE) {
|
|
|
|
say_file("digits/%c_f.wav", *p);
|
|
|
|
} else {
|
|
|
|
say_file("digits/%c.wav", *p);
|
|
|
|
}
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
say_file("digits/0.wav");
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
static switch_status_t fr_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
char *a, *b, *c, *d;
|
2008-07-28 16:13:52 +00:00
|
|
|
if (!(a = switch_core_session_strdup(session, tosay))) {
|
2007-10-17 19:52:43 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(b = strchr(a, '.'))) {
|
2008-07-28 16:13:52 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*b++ = '\0';
|
|
|
|
|
|
|
|
if (!(c = strchr(b, '.'))) {
|
2008-07-28 16:13:52 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*c++ = '\0';
|
|
|
|
|
|
|
|
if (!(d = strchr(c, '.'))) {
|
2008-07-28 16:13:52 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*d++ = '\0';
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
say_num(atoi(a), say_args->method);
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/dot.wav");
|
2010-03-07 19:34:05 +00:00
|
|
|
say_num(atoi(b), say_args->method);
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/dot.wav");
|
2010-03-07 19:34:05 +00:00
|
|
|
say_num(atoi(c), say_args->method);
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/dot.wav");
|
2010-03-07 19:34:05 +00:00
|
|
|
say_num(atoi(d), say_args->method);
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2008-07-28 16:13:52 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
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)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
int32_t t;
|
2010-03-08 06:50:27 +00:00
|
|
|
switch_time_t target = 0, target_now = 0;
|
|
|
|
switch_time_exp_t tm, tm_now;
|
|
|
|
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");
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
if (say_args->type == SST_TIME_MEASUREMENT) {
|
2007-10-17 19:52:43 +00:00
|
|
|
int64_t hours = 0;
|
|
|
|
int64_t minutes = 0;
|
|
|
|
int64_t seconds = 0;
|
|
|
|
int64_t r = 0;
|
|
|
|
|
|
|
|
if (strchr(tosay, ':')) {
|
|
|
|
char *tme = switch_core_session_strdup(session, tosay);
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = strrchr(tme, ':'))) {
|
|
|
|
*p++ = '\0';
|
|
|
|
seconds = atoi(p);
|
|
|
|
if ((p = strchr(tme, ':'))) {
|
|
|
|
*p++ = '\0';
|
|
|
|
minutes = atoi(p);
|
|
|
|
if (tme) {
|
|
|
|
hours = atoi(tme);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minutes = atoi(tme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
if ((seconds = atol(tosay)) <= 0) {
|
2009-01-25 21:23:07 +00:00
|
|
|
seconds = (int64_t) switch_epoch_time_now(NULL);
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (seconds >= 60) {
|
|
|
|
minutes = seconds / 60;
|
|
|
|
r = seconds % 60;
|
|
|
|
seconds = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minutes >= 60) {
|
|
|
|
hours = minutes / 60;
|
|
|
|
r = minutes % 60;
|
|
|
|
minutes = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
say_args->gender = SSG_FEMININE;
|
|
|
|
|
2007-10-17 19:52:43 +00:00
|
|
|
if (hours) {
|
|
|
|
say_num(hours, SSM_PRONOUNCED);
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/hour.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
/* TODO MINUIT */
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/0.wav");
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/hour.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minutes) {
|
|
|
|
say_num(minutes, SSM_PRONOUNCED);
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/minute.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
/* TODO Aucune idee quoi faire jouer icit */
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/0.wav");
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/minute.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (seconds) {
|
|
|
|
say_num(seconds, SSM_PRONOUNCED);
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/second.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2010-03-08 06:50:27 +00:00
|
|
|
/* TODO Aucune idee quoi faire jouer icit */
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("digits/0.wav");
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/second.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
if ((t = atol(tosay)) > 0) {
|
2007-10-17 19:52:43 +00:00
|
|
|
target = switch_time_make(t, 0);
|
2010-03-08 06:50:27 +00:00
|
|
|
target_now = switch_micro_time_now();
|
2007-10-17 19:52:43 +00:00
|
|
|
} else {
|
2009-01-25 21:23:07 +00:00
|
|
|
target = switch_micro_time_now();
|
2010-03-08 06:50:27 +00:00
|
|
|
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_now, target_now);
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
switch (say_args->type) {
|
2007-10-17 19:52:43 +00:00
|
|
|
case SST_CURRENT_DATE_TIME:
|
|
|
|
say_date = say_time = 1;
|
|
|
|
break;
|
|
|
|
case SST_CURRENT_DATE:
|
|
|
|
say_date = 1;
|
|
|
|
break;
|
|
|
|
case SST_CURRENT_TIME:
|
|
|
|
say_time = 1;
|
|
|
|
break;
|
2010-03-08 06:50:27 +00:00
|
|
|
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;
|
|
|
|
|
2007-10-17 19:52:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
if (say_today) {
|
|
|
|
say_file("time/today.wav");
|
|
|
|
}
|
|
|
|
if (say_yesterday) {
|
|
|
|
say_file("time/yesterday.wav");
|
|
|
|
}
|
|
|
|
if (say_dow) {
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("time/day-%d.wav", tm.tm_wday);
|
2010-03-08 06:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
say_args->gender = SSG_FEMININE;
|
|
|
|
say_num(tm.tm_mday, SSM_PRONOUNCED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (say_month) {
|
2007-10-17 19:52:43 +00:00
|
|
|
say_file("time/mon-%d.wav", tm.tm_mon);
|
2010-03-08 06:50:27 +00:00
|
|
|
}
|
|
|
|
if (say_year) {
|
|
|
|
say_args->gender = SSG_MASCULINE;
|
2007-10-17 19:52:43 +00:00
|
|
|
say_num(tm.tm_year + 1900, SSM_PRONOUNCED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (say_time) {
|
2010-03-08 06:50:27 +00:00
|
|
|
if (say_date || say_today || say_yesterday || say_dow) {
|
|
|
|
say_file("time/at.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
2010-03-08 06:50:27 +00:00
|
|
|
say_args->gender = SSG_FEMININE;
|
|
|
|
say_num(tm.tm_hour, SSM_PRONOUNCED);
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
say_file("time/hour.wav");
|
2007-10-17 19:52:43 +00:00
|
|
|
|
2010-03-08 06:50:27 +00:00
|
|
|
if (tm.tm_min) {
|
2007-10-17 19:52:43 +00:00
|
|
|
say_num(tm.tm_min, SSM_PRONOUNCED);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
static switch_status_t fr_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
char sbuf[16] = ""; /* enough for 999,999,999,999.99 (w/o the commas or leading $) */
|
|
|
|
char *dollars = NULL;
|
|
|
|
char *cents = NULL;
|
|
|
|
|
|
|
|
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
dollars = sbuf;
|
|
|
|
|
|
|
|
if ((cents = strchr(sbuf, '.'))) {
|
|
|
|
*cents++ = '\0';
|
|
|
|
if (strlen(cents) > 2) {
|
|
|
|
cents[2] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If positive sign - skip over" */
|
|
|
|
if (sbuf[0] == '+') {
|
|
|
|
dollars++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If negative say "negative" */
|
|
|
|
if (sbuf[0] == '-') {
|
|
|
|
say_file("currency/negative.wav");
|
|
|
|
dollars++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Say dollar amount */
|
2010-03-07 19:34:05 +00:00
|
|
|
fr_say_general_count(session, dollars, say_args, args);
|
2007-10-17 19:52:43 +00:00
|
|
|
if (atoi(dollars) == 1) {
|
|
|
|
say_file("currency/dollar.wav");
|
|
|
|
} else {
|
|
|
|
say_file("currency/dollars.wav");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Say "and" */
|
|
|
|
say_file("currency/and.wav");
|
|
|
|
|
|
|
|
/* Say cents */
|
|
|
|
if (cents) {
|
2010-03-07 19:34:05 +00:00
|
|
|
fr_say_general_count(session, cents, say_args, args);
|
2007-10-17 19:52:43 +00:00
|
|
|
if (atoi(cents) == 1) {
|
|
|
|
say_file("currency/cent.wav");
|
|
|
|
} else {
|
|
|
|
say_file("currency/cents.wav");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
say_file("digits/0.wav");
|
|
|
|
say_file("currency/cents.wav");
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
static switch_status_t fr_say(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch_say_callback_t say_cb = NULL;
|
|
|
|
|
2010-03-07 19:34:05 +00:00
|
|
|
switch (say_args->type) {
|
2007-10-17 19:52:43 +00:00
|
|
|
case SST_NUMBER:
|
|
|
|
case SST_ITEMS:
|
|
|
|
case SST_PERSONS:
|
|
|
|
case SST_MESSAGES:
|
2007-10-17 20:17:00 +00:00
|
|
|
say_cb = fr_say_general_count;
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
case SST_TIME_MEASUREMENT:
|
|
|
|
case SST_CURRENT_DATE:
|
|
|
|
case SST_CURRENT_TIME:
|
|
|
|
case SST_CURRENT_DATE_TIME:
|
2010-03-08 06:50:27 +00:00
|
|
|
case SST_SHORT_DATE_TIME:
|
2007-10-17 20:17:00 +00:00
|
|
|
say_cb = fr_say_time;
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
case SST_IP_ADDRESS:
|
2007-10-17 20:17:00 +00:00
|
|
|
say_cb = fr_ip;
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
case SST_NAME_SPELLED:
|
|
|
|
case SST_NAME_PHONETIC:
|
2007-10-17 20:17:00 +00:00
|
|
|
say_cb = fr_spell;
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
case SST_CURRENCY:
|
2007-10-17 20:17:00 +00:00
|
|
|
say_cb = fr_say_money;
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-07 19:34:05 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", say_args->type);
|
2007-10-17 19:52:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (say_cb) {
|
2010-03-07 19:34:05 +00:00
|
|
|
return say_cb(session, tosay, say_args, args);
|
2007-10-17 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:17:00 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_say_fr_load)
|
2007-10-17 19:52:43 +00:00
|
|
|
{
|
|
|
|
switch_say_interface_t *say_interface;
|
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
|
|
|
say_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_SAY_INTERFACE);
|
2007-10-17 20:17:00 +00:00
|
|
|
say_interface->interface_name = "fr";
|
|
|
|
say_interface->say_function = fr_say;
|
2007-10-17 19:52:43 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2008-01-27 05:02:52 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2008-01-27 05:02:52 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 19:12:26 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2008-01-27 05:02:52 +00:00
|
|
|
*/
|