예제 #1
0
static switch_status_t hr_ip(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char *a, *b, *c, *d;
	if (!(a = switch_core_session_strdup(session, tosay))) {
		return SWITCH_STATUS_FALSE;
	}

	if (!(b = strchr(a, '.'))) {
		return SWITCH_STATUS_FALSE;
	}

	*b++ = '\0';

	if (!(c = strchr(b, '.'))) {
		return SWITCH_STATUS_FALSE;
	}

	*c++ = '\0';

	if (!(d = strchr(c, '.'))) {
		return SWITCH_STATUS_FALSE;
	}

	*d++ = '\0';

	say_num(atoi(a), say_args->method, "");
	say_file("digits/dot.wav");
	say_num(atoi(b), say_args->method, "");
	say_file("digits/dot.wav");
	say_num(atoi(c), say_args->method, "");
	say_file("digits/dot.wav");
	say_num(atoi(d), say_args->method, "");

	return SWITCH_STATUS_SUCCESS;
}
예제 #2
0
static switch_status_t hu_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";
	char *forint;

	if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	forint = sbuf;

	if (sbuf[0] == '+') {
		forint++;
	}

	if (sbuf[0] == '-') {
		say_file("currency/negative.wav");
		forint++;
	}

	hu_say_general_count(session, forint, say_args, args);
	say_file("currency/forint.wav");

	return SWITCH_STATUS_SUCCESS;
}
예제 #3
0
static switch_status_t de_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	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 = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1))) {
		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 */
	if (atoi(dollars) == 1) {
		say_file("digits/s-1.wav");
		say_file("currency/dollar.wav");
	} else {
		de_say_general_count(session, dollars, say_args, args);
		say_file("currency/dollars.wav");
	}

	/* Say cents */
	if (cents) {
		/* Say "and" */
		say_file("currency/and.wav");
		if (atoi(cents) == 1) {
			say_file("digits/s-1.wav");
			say_file("currency/cent.wav");
		} else {
			de_say_general_count(session, cents, say_args, args);
			say_file("currency/cents.wav");
		}
	} else {
		say_file("digits/0.wav");
		say_file("currency/cents.wav");
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #4
0
static switch_status_t de_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
    int in;
    int x = 0;
    int places[9] = { 0 };
    char sbuf[128] = "";
    switch_status_t status;

    if (say_args->method == SSM_ITERATED) {
        if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
            char *p;
            for (p = tosay; p && *p; p++) {
                say_file("digits/%c.wav", *p);
            }
        } else {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
            return SWITCH_STATUS_GENERR;
        }
        return SWITCH_STATUS_SUCCESS;
    }

    if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || 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) {   /*fills the places-array with tosay(resp. in) from tail to front e.g. 84371 would be places[|1|7|3|4|8|0|0|0|], up to 1 billion minus 1*/
        for (x = 8; x >= 0; x--) {
            int num = (int) pow(10, x);
            if ((places[(uint32_t) x] = in / num)) {
                in -= places[(uint32_t) x] * num;
            }
        }

        switch (say_args->method) {
        case SSM_COUNTED:
        case SSM_PRONOUNCED:
            if ((status = play_group(SSM_PRONOUNCED, say_args->gender, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
                return status;
            }
            if ((status = play_group(SSM_PRONOUNCED, say_args->gender, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
                return status;
            }
            if ((status = play_group(say_args->method, say_args->gender, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
                return status;
            }
            break;
        default:
            break;
        }
    } else {
        say_file("digits/0.wav");
    }

    return SWITCH_STATUS_SUCCESS;
}
예제 #5
0
static switch_status_t fa_say_telephone(switch_core_session_t *session,	char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char *phone_number;
	int tosay_length = 0;

	if( !tosay || !strlen(tosay) )
	{
		return SWITCH_STATUS_SUCCESS;
	}

	if ((phone_number = strchr(tosay,'-')))
	{
		*phone_number++ = '\0';
		fa_say_telephone(session,tosay,say_args,args);
		fa_say_telephone(session,phone_number,say_args,args);
		return SWITCH_STATUS_SUCCESS;
	}

	tosay_length = strlen(tosay);
	if( tosay_length == 1 )
	{
		say_file("digits/%d.wav",tosay[0] - 48);
	}
	else if ( tosay[0] == '0' )
	{
		if( tosay[1] == '0' )
		{
			say_file("digits/00.wav");
			fa_say_telephone(session,tosay + 2,say_args,args);
		}
		else
		{
			say_file("digits/0.wav");
			fa_say_telephone(session,tosay + 1,say_args,args);
		}
	}
	else if ( tosay_length % 2 )
	{
		play_group(SSM_PRONOUNCED,tosay[0] - 48,tosay[1] - 48,tosay[2] - 48,NULL,session,args);
		fa_say_telephone(session,tosay + 3,say_args,args);
	}
	else
	{
		if ( tosay_length == 10 && (tosay[0] != '2' || tosay[1] != '1') )
		{
			play_group(SSM_PRONOUNCED,tosay[0] - 48,tosay[1] - 48,tosay[2] - 48,NULL,session,args);
			fa_say_telephone(session,tosay + 3,say_args,args);
		}
		else
		{
			play_group(SSM_PRONOUNCED,0,tosay[0] - 48,tosay[1] - 48,NULL,session,args);
			fa_say_telephone(session,tosay + 2,say_args,args);
		}
	}
	return SWITCH_STATUS_SUCCESS;
}
예제 #6
0
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)
{

	if (a) {
		say_file("digits/%d.wav", a);
		say_file("digits/honderd.wav");
	}

	if (b) {
		if (b > 1) {
			if (c) {
				say_file("digits/%d-en.wav", c);
			}
			say_file("digits/%d0.wav", b);
		} else {
			say_file("digits/%d%d.wav", b, c);
		}
		c = 0;
	}

	if (c) {
		say_file("digits/%d.wav", c);
		if (method == SSM_COUNTED) {
			say_file("digits/h-%d.wav", c);
		} else {
			say_file("digits/%d.wav", c);
		}
	}

	if (what && (a || b || c)) {
		say_file(what);
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #7
0
static switch_status_t play_group(switch_say_method_t method, switch_say_gender_t gender, 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;

	/* 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/hundred.wav");
	}

	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 (method == SSM_COUNTED) {
				say_file("digits/h-%d%d.wav", b, c);
			} else {
				say_file("digits/%d%d.wav", b, c);
			}
		} else {
			say_file("digits/%d0.wav", b);
		}
	}

	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 (method == SSM_COUNTED) {
			say_file("digits/h-%d.wav", fVal);
		} else {
			if (b != 1 && c == 1 && gender == SSG_FEMININE) {
				say_file("digits/%d_f.wav", fVal);
			} else {
				say_file("digits/%d.wav", fVal);
			}
		}
	}

	if (what && (a || b || c)) {
		say_file(what);
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #8
0
static switch_status_t es_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int in;
	int x = 0;
	int places[9] = { 0 };
	char sbuf[13] = "";
	switch_status_t status;

	if (!(tosay = switch_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);
			if ((places[(uint32_t) x] = in / num)) {
				in -= places[(uint32_t) x] * num;
			}
		}

		switch (say_args->method) {
		case SSM_COUNTED:
		case SSM_PRONOUNCED:
			if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(say_args->method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			break;
		case SSM_ITERATED:
			{
				char *p;
				for (p = tosay; p && *p; p++) {
					say_file("digits/%c.wav", *p);
				}
			}
			break;
		default:
			break;
		}
	} else {
		say_file("digits/0.wav");
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #9
0
static switch_status_t play_group(switch_say_method_t method, char* gen, int a, int b, int c, char *what, int tosay, switch_core_session_t *session,
								  switch_input_args_t *args)
{
	if (a) {
		say_file("digits/%d.wav", a);
		say_file("digits/hundred.wav");
	}

	if (b) {
		if (b > 1) {
			if ((c == 0) && (method == SSM_COUNTED)) {
				say_file("digits/h-%d0.wav", b);
			} else {
				say_file("digits/%d0.wav", b);
			}
		} else {
			say_file("digits/%d%d%s.wav", b, c, gen);
			c = 0;
		}
	}

	if (c) {
		if (method == SSM_COUNTED) {
			say_file("digits/h-%d%s.wav", c, gen);
		} else {
			say_file("digits/%d%s.wav", c, gen);
		}
	}

	if (what && (a || b || c)) {
		say_file(what);
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #10
0
static switch_status_t hr_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;
}
예제 #11
0
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)
{
	if (a) {
		if ( !b && !c )
		{
			if( method == SSM_COUNTED )
			{
				say_file("digits/%d00om.wav", a);
			}
			else
				say_file("digits/%d00.wav", a);
			b = c = 0;
		}
		else
			say_file("digits/%d00+.wav", a);
	}

	if (b) {
		if ( !c || b == 1 )
		{
			if( method == SSM_COUNTED )
			{
				say_file("digits/%d%dom.wav", b, c);
			}
			else
				say_file("digits/%d%d.wav", b, c);
			c = 0;
		}
		else
			say_file("digits/%d0+.wav", b);
	}

	if (c) {
		if (method == SSM_COUNTED) {
			say_file("digits/%dom.wav", c);
		} else {
			say_file("digits/%d.wav", c);
		}
	}

	if (what && (a || b || c)) {
		say_file(what);
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #12
0
static switch_status_t fa_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
	char *rials = NULL;
	char *cents = NULL;

	if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
		/* valid characters are 0 - 9, period (.), minus (-), and plus (+) - remove all others */
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	rials = sbuf;

	if ((cents = strchr(sbuf, '.'))) {
		*cents++ = '\0';
		if (strlen(cents) > 2) {
			cents[2] = '\0';
		}
	}

	/* If positive sign - skip over" */
	if (sbuf[0] == '+') {
		say_file("currency/positive-e.wav");
		rials++;
	}

	/* If negative say "negative" */
	if (sbuf[0] == '-') {
		say_file("currency/negative-e.wav");
		rials++;
	}

	/* Say rial amount */
	fa_say_general_count(session, rials, say_args, args);
	say_file("currency/rials.wav");

	return SWITCH_STATUS_SUCCESS;
}
예제 #13
0
static switch_status_t zh_CN_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
	char dbuf[16] = "";			/* enough for digits/x.wav */
	char *yuan = NULL;
	char *rest = NULL;
	int i;

	if (strlen(tosay) > 15 || !switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1)) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	yuan = sbuf;

	if ((rest = strchr(sbuf, '.'))) {
		*rest++ = '\0';
	}

	/* If positive sign - skip over" */
	if (sbuf[0] == '+') {
		yuan++;
	}

	/* If negative say "negative" */
	if (sbuf[0] == '-') {
		say_file("currency/negative.wav");
		yuan++;
	}

	/* Say dollar amount */
	zh_say_general_count(session, yuan, say_args, args);
	say_file("currency/yuan.wav");

	if (!rest) return SWITCH_STATUS_SUCCESS;

	/* Say cents */
	for (i=0; *rest; i++, rest++) {
	sprintf(dbuf, "digits/%c.wav", *rest);
		say_file(dbuf);
		if (i == 0) {
			say_file("currency/jiao.wav");
		} else if (i == 1) {
			say_file("currency/fen.wav");
		} else if (i == 2) {
			say_file("currency/li.wav");
		}  /* else just say the rest of digits */
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #14
0
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;
	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");

	if (say_args->type == SST_TIME_MEASUREMENT) {
		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 {
			if ((seconds = atol(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

			if (seconds >= 60) {
				minutes = seconds / 60;
				r = seconds % 60;
				seconds = r;
			}

			if (minutes >= 60) {
				hours = minutes / 60;
				r = minutes % 60;
				minutes = r;
			}
		}

		say_args->gender = SSG_FEMININE;

		if (hours) {
			say_num(hours, SSM_PRONOUNCED);
			say_file("time/hour.wav");
		} else {
			/* TODO MINUIT */
			say_file("digits/0.wav");
			say_file("time/hour.wav");
		}

		if (minutes) {
			say_num(minutes, SSM_PRONOUNCED);
			say_file("time/minute.wav");
		} else {
			/* TODO Aucune idee quoi faire jouer icit */
			say_file("digits/0.wav");
			say_file("time/minute.wav");
		}

		if (seconds) {
			say_num(seconds, SSM_PRONOUNCED);
			say_file("time/second.wav");
		} else {
			/* TODO Aucune idee quoi faire jouer icit */
			say_file("digits/0.wav");
			say_file("time/second.wav");
		}

		return SWITCH_STATUS_SUCCESS;
	}

	if ((t = atol(tosay)) > 0) {
		target = switch_time_make(t, 0);
		target_now = switch_micro_time_now();
	} else {
		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_now, target_now);
	}

	switch (say_args->type) {
	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;
	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:
		break;
	}

	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);
	}

	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) {
		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);
	}

	if (say_time) {
		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);

		say_file("time/hour.wav");

		if (tm.tm_min) {
			say_num(tm.tm_min, SSM_PRONOUNCED);
		}

	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #15
0
static switch_status_t it_say_general_count(switch_core_session_t *session,	char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int in;
	int places_count = 0;
	int places[9] = { 0 };
	char sbuf[128] = "";
	switch_status_t status;

	if (say_args->method == SSM_ITERATED) {
		if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
			char *p;
			for (p = tosay; p && *p; p++) {
				say_file("digits/%c.wav", *p);
			}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
			return SWITCH_STATUS_GENERR;
		}
		return SWITCH_STATUS_SUCCESS;
	}

	if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || strlen(tosay) > 9) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	/* Get in */
	in = atoi(tosay);

	/* Check if number too big */
	if (in > 999999999) {
		/* Fail */
		return SWITCH_STATUS_FALSE;
	}

	/* Check if number isn't zero */
	if (in != 0) {

		/* Init x to 0 */
		places_count = 0;

		/* Loop until in is greater than zero */
		do {
			/* Get last digit */
			places[places_count] = in % 10;

			/* Drop last digit */
			in = in / 10;
		}
		while (in > 0 && ++places_count > 0 /* fake check to put in while */ );

		switch (say_args->method) {
		case SSM_COUNTED:
		case SSM_PRONOUNCED:

			/* Check for milions */
			if (places_count > 5) {
				/* Check if the millions digit is one (digit 6 = 1, digit 7 and 8 = 0) */
				if (places[6] == 1 && places[7] == 0 && places[8] == 0) {
					say_file("digits/un.wav");
					say_file("digits/million.wav");
				} else {
					/* Play millions group (digits/million.wav should be digits/millions.wav) */
					if ((status =
						 play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
						return status;
					}
				}

			}

			/* Check for thousands */
			if (places_count > 2) {
				if (places[3] == 1 && places[4] == 0 && places[5] == 0) {
					say_file("digits/thousand.wav");
				} else {
					/* Play thousand group */
					if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3],
											 "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
						return status;
					}
				}
			}

			/* Play last group */
			if ((status = play_group(say_args->method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			break;
		default:
			break;
		}
	} else {
		say_file("digits/0.wav");
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #16
0
static switch_status_t hu_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int32_t t;
	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");

	if (say_args->type == SST_TIME_MEASUREMENT) {
		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 {
			if ((seconds = atol(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

			if (seconds >= 60) {
				minutes = seconds / 60;
				r = seconds % 60;
				seconds = r;
			}

			if (minutes >= 60) {
				hours = minutes / 60;
				r = minutes % 60;
				minutes = r;
			}
		}

		if (hours) {
			say_num(hours, SSM_PRONOUNCED);
			say_file("time/hour.wav");
		} else {
			say_file("digits/0.wav");
			say_file("time/hour.wav");
		}

		if (minutes) {
			say_num(minutes, SSM_PRONOUNCED);
			say_file("time/minute.wav");
		} else {
			say_file("digits/0.wav");
			say_file("time/minute.wav");
		}

		if (seconds) {
			say_num(seconds, SSM_PRONOUNCED);
			say_file("time/second.wav");
		} else {
			say_file("digits/0.wav");
			say_file("time/second.wav");
		}

		return SWITCH_STATUS_SUCCESS;
	}

	if ((t = atol(tosay)) > 0) {
		target = switch_time_make(t, 0);
		target_now = switch_micro_time_now();
	} else {
		target = switch_micro_time_now();
		target_now = switch_micro_time_now();
	}

	if (tz) {
		int check = atoi(tz);
		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]\n", 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);
	}

	switch (say_args->type) {
	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;
	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:
		break;
	}

	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);
	}

	if (say_date) {
		say_year = say_month = say_day = say_dow = 1;
		say_today = say_yesterday = 0;
	}

	if (say_year) {
		say_num(tm.tm_year + 1900, SSM_PRONOUNCED);
	}

	if (say_month) {
		say_file("time/mon-%d.wav", tm.tm_mon);
	}
	if (say_day) {
		say_num(tm.tm_mday, SSM_PRONOUNCED);
	}

	if (say_time) {
		say_num(tm.tm_hour, SSM_PRONOUNCED);
		say_file("time/hour.wav");

		say_num(tm.tm_min, SSM_PRONOUNCED);
		say_file("time/minute.wav");

	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #17
0
static switch_status_t play_group(switch_say_method_t method, switch_say_gender_t gender, int a, int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
{

    if (a) {
        /*german nominativ for "one" in numbers like 21, 171, 4591 is flexed("ein" instead of "eins"), 2-9 are not*/
        if ( a == 1 ) {
            say_file("digits/s-1.wav");
        } else {
            say_file("digits/%d.wav", a);
        }
        say_file("digits/hundred.wav");
    }

    if (b) {
        if (b > 1) {
            /*german nominativ for "one" in numbers like 21, 171, 4591 is flexed, 2-9 are not*/
            if ( c == 1 ) {
                say_file("digits/s-1.wav");
            } else {
                say_file("digits/%d.wav", c);
            }
            say_file("currency/and.wav");
            if (method == SSM_COUNTED) {
                say_file("digits/h-%d0.wav", b);
            } else {
                say_file("digits/%d0.wav", b);
            }
        } else {
            if (method == SSM_COUNTED) {
                say_file("digits/h-%d%d.wav", b, c);
            } else {
                say_file("digits/%d%d.wav", b, c);
            }
        }
        c = 0;
    }

    if (c) {
        if (method == SSM_COUNTED) {
            say_file("digits/h-%d.wav", c);
        } else {
            /*"one" used as an article is feminine or masculine in german, e.g. voicemail-message is feminine
            only applies to the likes of 1, 101, 1001 etc.*/
            if ( b == 0  && c == 1 && gender == SSG_FEMININE ) {
                say_file("digits/%d_f.wav", c);
            } else if ( b == 0 && c == 1 && what ) {
                say_file("digits/s-1.wav");
            } else {
                say_file("digits/%d.wav", c);
            }
        }
    }

    if (what && (a || b || c)) {
        say_file(what);
    }

    return SWITCH_STATUS_SUCCESS;
}
예제 #18
0
static switch_status_t play_group(say_type_t say_type, casus_t casus, int a, int b, int c,
								  unit_t what, switch_core_session_t *session, switch_input_args_t *args)
{
	if (a) {
		if (((b == 0) && (c == 0)) || (matrix[casus][say_type].all == 1)) {	//если b и с равны 0 то сказать шестьсот, сестисотый, шестисотая
			if (what == million) {	//префикс           число          окончание
				say_file("digits/%s%d00%s.wav", matrix[casus][say_type].million[12], a, matrix[casus][say_type].million[13]);
				say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
			} else if (what == thousand) {
				say_file("digits/%s%d00%s.wav", matrix[casus][say_type].thousand[12], a, matrix[casus][say_type].thousand[13]);
				say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
			} else {
				say_file("digits/%s%d00%s.wav", matrix[casus][say_type].num[6], a, matrix[casus][say_type].num[7]);
			}
		} else {				//если дальше есть цифры то тысячи и миллионы не прозносить пока
			say_file("digits/%d00.wav", a);
		}
	}

	if (b) {
		if (b > 1) {			//если 20 и больше
			if ((c == 0) || (matrix[casus][say_type].all == 1)) {	//если с равны 0 то сказать 20, двадцати, двадцатая
				if (what == million) {	//префикс            число          окончание
					say_file("digits/%s%d0%s.wav", matrix[casus][say_type].million[12], b, matrix[casus][say_type].million[13]);
					say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
				} else if (what == thousand) {
					say_file("digits/%s%d0%s.wav", matrix[casus][say_type].thousand[12], b, matrix[casus][say_type].thousand[13]);
					say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
				} else {
					say_file("digits/%s%d0%s.wav", matrix[casus][say_type].num[6], b, matrix[casus][say_type].num[7]);
				}
			} else {			//если есть дальше цифры
				say_file("digits/%d0.wav", b);
			}
		} else {				//от 10 до 19
			if (what == million) {
				say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].million[12], b, c, matrix[casus][say_type].million[13]);
				say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
			} else if (what == thousand) {
				say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].thousand[12], b, c, matrix[casus][say_type].thousand[13]);
				say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
			} else {			//просто произнести цифры с префиксом и окончанием
				say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].num[6], b, c, matrix[casus][say_type].num[7]);
			}
			c = 0;
		}
	}

	if (c || what == zero) {
		if (c <= 5) {
			if (what == million) {
				if ((strlen(matrix[casus][say_type].million[c * 2])) > 0) {	// не произносить если не заданно например 1 миллион а просто миллион
					say_file("digits/%s.wav", matrix[casus][say_type].million[c * 2])
				}
				say_file("digits/%s.wav", matrix[casus][say_type].million[c * 2 + 1]);
			} else if (what == thousand) {
				if ((strlen(matrix[casus][say_type].thousand[c * 2])) > 0) {	// не произносить если не заданно например одна тысячас  а просто тысяча
					say_file("digits/%s.wav", matrix[casus][say_type].thousand[c * 2])
				}
				say_file("digits/%s.wav", matrix[casus][say_type].thousand[c * 2 + 1]);
			} else {			//просто произнести цифры с префиксом и окончанием
				say_file("digits/%s.wav", matrix[casus][say_type].num[c]);
			}
		} else {				/* больше 5 */
예제 #19
0
static switch_status_t hr_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";
	char *kuna = NULL;
	char *lipa = NULL;
	
	int zadnja_kuna = 0;
	int predzadnja_kuna = 0;
	int zadnja_lipa = 0;
	int predzadnja_lipa = 0;

	if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1))) 
	{
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	kuna = sbuf;
	
	if ((lipa = strchr(sbuf, '.'))) 
	{
		*lipa++ = '\0';
		if (strlen(lipa) > 2) 
		{
			lipa[2] = '\0';
		}
	}

	if (sbuf[0] == '+') 
	{
		kuna++;
	}

	if (sbuf[0] == '-') 
	{
		say_file("currency/negative.wav");
		kuna++;
	}

	if (kuna != NULL && strlen(kuna) > 0)
		zadnja_kuna = (int) ((char) *(kuna + strlen(kuna) - 1) - '0');
		
	if (kuna != NULL && strlen(kuna) > 1)
		predzadnja_kuna = (int) ((char) *(kuna + strlen(kuna) - 2) - '0');
		
		
	if (predzadnja_kuna == 1)
	{
		hr_say_count(session, "", kuna, say_args, args);
		say_file("currency/kuna.wav");
	}
	else
	{
		switch(zadnja_kuna)
		{
			case 1:
				hr_say_count(session, "a", kuna, say_args, args);
				say_file("currency/kuna.wav");
				break;

			case 0:				
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
				hr_say_count(session, "", kuna, say_args, args);
				say_file("currency/kuna.wav");
				break;
				
			case 2:
				hr_say_count(session, "je", kuna, say_args, args);
				say_file("currency/kune.wav");
				break;
				
			case 3:
			case 4:
				hr_say_count(session, "", kuna, say_args, args);
				say_file("currency/kune.wav");
				break;
		}
	}
	
	if (lipa)
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "lipa:%s \n", lipa);
	else
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "lipa: NULL \n");
	
	if (lipa)
	{
		/* Say "and" */
		say_file("currency/and.wav");
	
		if (lipa != NULL && strlen(lipa) > 0)
			zadnja_lipa = (int) ((char) *(lipa + strlen(lipa) - 1) - '0');
		
		if (lipa != NULL && strlen(lipa) > 1)
			predzadnja_lipa = (int) ((char) *(lipa + strlen(lipa) - 2) - '0');
		
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "zadnja_lipa:%d \n", zadnja_lipa);	
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "predzadnja_lipa:%d \n", predzadnja_lipa);	
			
		if (predzadnja_lipa == 1)
		{
			hr_say_count(session, "", lipa, say_args, args);
			say_file("currency/lipa.wav");
		}
		else
		{
			switch(zadnja_lipa)
			{
				case 1:
					hr_say_count(session, "a", lipa, say_args, args);
					say_file("currency/lipa.wav");
					break;

				case 0:					
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
					hr_say_count(session, "", lipa, say_args, args);
					say_file("currency/lipa.wav");
					break;
					
				case 2:
					hr_say_count(session, "je", lipa, say_args, args);
					say_file("currency/lipa.wav");
					break;
					
				case 3:
				case 4:
					hr_say_count(session, "", lipa, say_args, args);
					say_file("currency/lipe.wav");
					break;
			}
		}
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #20
0
static switch_status_t de_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
    int32_t t;
    switch_time_t target = 0;
    switch_time_exp_t tm;
    uint8_t say_date = 0, say_time = 0;

    if (say_args->type == SST_TIME_MEASUREMENT) {
        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 {
            if ((seconds = atoi(tosay)) <= 0) {
                seconds = (int64_t) switch_epoch_time_now(NULL);
            }

            if (seconds >= 60) {
                minutes = seconds / 60;
                r = seconds % 60;
                seconds = r;
            }

            if (minutes >= 60) {
                hours = minutes / 60;
                r = minutes % 60;
                minutes = r;
            }
        }

        if (hours) {
            say_num(hours, SSM_PRONOUNCED);
            if (hours == 1) {
                say_file("time/hour.wav");
            } else {
                say_file("time/hours.wav");
            }
        } else {
            say_file("digits/0.wav");
            say_file("time/hours.wav");
        }

        if (minutes) {
            say_num(minutes, SSM_PRONOUNCED);
            if (minutes == 1) {
                say_file("time/minute.wav");
            } else {
                say_file("time/minutes.wav");
            }
        } else {
            say_file("digits/0.wav");
            say_file("time/minutes.wav");
        }

        if (seconds) {
            say_num(seconds, SSM_PRONOUNCED);
            if (seconds == 1) {
                say_file("time/second.wav");
            } else {
                say_file("time/seconds.wav");
            }
        } else {
            say_file("digits/0.wav");
            say_file("time/seconds.wav");
        }

        return SWITCH_STATUS_SUCCESS;
    }

    if ((t = atoi(tosay)) > 0) {
        target = switch_time_make(t, 0);
    } else {
        target = switch_micro_time_now();
    }
    switch_time_exp_lt(&tm, target);

    switch (say_args->type) {
    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;
    default:
        break;
    }

    if (say_date) {
        say_file("time/day-%d.wav", tm.tm_wday);
        say_file("time/mon-%d.wav", tm.tm_mon);
        say_num(tm.tm_mday, SSM_COUNTED);
        say_num(tm.tm_year + 1900, SSM_PRONOUNCED);
    }

    if (say_time) {
        int32_t hour = tm.tm_hour, pm = 0;

        if (hour > 12) {
            hour -= 12;
            pm = 1;
        } else if (hour == 12) {
            pm = 1;
        } else if (hour == 0) {
            hour = 12;
            pm = 0;
        }

        say_num(hour, SSM_PRONOUNCED);
        say_file("time/oclock.wav");

        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);
        }

        say_file("time/%s.wav", pm ? "p-m" : "a-m");
    }

    return SWITCH_STATUS_SUCCESS;
}
예제 #21
0
static switch_status_t hr_say_count(switch_core_session_t *session, char* gen,
											char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int in;
	int x = 0;
	int places[9] = { 0 };
	char sbuf[13] = "";
	char milion[64] = "";
	char tisucu[64] = "";
	char tgen[8] = "";
	char mgen[8] = "";
	
	
	int number;
	switch_status_t status;

	strcpy(tgen, gen);
	
	if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || strlen(tosay) > 9) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	in = atoi(tosay);
	number = in;

	if (in != 0) {
		for (x = 8; x >= 0; x--) {
			int num = (int) pow(10, x);
			if ((places[(uint32_t) x] = in / num)) {
				in -= places[(uint32_t) x] * num;
			}
		}

		switch (say_args->method) {
		case SSM_COUNTED:
		case SSM_PRONOUNCED:
			{
				if (places[6] == 1)
					strcpy(milion, "digits/milijun.wav");
				else
					strcpy(milion, "digits/milijuna.wav");
				
				if (places[4] == 1)	
				{
					strcpy(tisucu, "digits/thousands-a.wav");
				}
				else if (places[4] == 0)
				{
					switch(places[3])
					{
						case 1:
							strcpy(tisucu, "digits/thousands-a.wav");
							strcpy(tgen, "a");
							break;
							
						case 5:
						case 6:
						case 7:
						case 8:
						case 9:
							strcpy(tisucu, "digits/thousands-a.wav");
							break;
							
						case 2:
							strcpy(tgen, "je");
							strcpy(tisucu, "digits/thousands-e.wav");
							break;
							
						case 3:
						case 4:
							strcpy(tisucu, "digits/thousands-e.wav");
							break;
					}
				}
				else
				{
					switch(places[3])
					{
						case 1:
							strcpy(tisucu, "digits/thousands-a.wav");
							strcpy(tgen, "a");
							break;
							
						case 5:
						case 6:
						case 7:
						case 8:
						case 9:
							strcpy(tisucu, "digits/thousands-a.wav");
							break;
							
						case 2:
							strcpy(tisucu, "digits/thousands-e.wav");
							strcpy(tgen, "je");
							break;
							
						case 3:
						case 4:
							strcpy(tisucu, "digits/thousands-e.wav");
							break;
					}
				}

				
				if ((status =
					 play_group(SSM_PRONOUNCED, mgen, places[8], places[7], places[6], milion, number, session, args)) != SWITCH_STATUS_SUCCESS) {
					return status;
				}
				if ((status =
					 play_group(SSM_PRONOUNCED, tgen, places[5], places[4], places[3], tisucu, number, session, args)) != SWITCH_STATUS_SUCCESS) {
					return status;
				}
				if ((status = play_group(say_args->method, gen, places[2], places[1], places[0], NULL, number, session, args)) != SWITCH_STATUS_SUCCESS) {
					return status;
				}
		}
			break;
		case SSM_ITERATED:
			{
				char *p;
				for (p = tosay; p && *p; p++) {
					say_file("digits/%c.wav", *p);
				}
			}
			break;
		default:
			break;
		}
	}
	/* else {
		say_file("digits/0.wav");
	}*/

	return SWITCH_STATUS_SUCCESS;
}
예제 #22
0
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)
{
	if (a) {
		switch (a) {
		case 1:
			if (b || c) {
				say_file("digits/hundred.wav");
			} else {
				say_file("digits/100.wav");
			}
			break;
		case 5:
			say_file("digits/500.wav");
			break;
		case 7:
			say_file("digits/700.wav");
			break;
		case 9:
			say_file("digits/900.wav");
			break;
		default:
			say_file("digits/%d.wav", a);
			say_file("digits/hundred.wav");
			break;
		}
	}

	if (b) {
		if (b > 1) {
			switch (b) {
			case 2:
				if (method != SSM_COUNTED) {
					if (c) {
						say_file("digits/veinti.wav");
					} else {
						say_file("digits/20.wav");
					}
					break;
				}

			default:
				if ((b < 4) && (method == SSM_COUNTED)) {
					say_file("digits/h-%d0.wav", b);
				} else {
					say_file("digits/%d0.wav", b);
					if (c) {
						say_file("currency/and.wav");
					}
				}
				break;
			}
		} else {
			say_file("digits/%d%d.wav", b, c);
			c = 0;
		}
	}
	if (c) {
		if (method == SSM_COUNTED) {
			say_file("digits/h-%d.wav", c);
		} else {
			say_file("digits/%d.wav", c);
		}
	}
	if (what && (a || b || c)) {
		say_file(what);
	}
	return SWITCH_STATUS_SUCCESS;
}
예제 #23
0
static switch_status_t th_say_general_count(switch_core_session_t *session,	char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int in;
	char sbuf[128] = "";
	char digits[11];
	int i;

	if (say_args->method == SSM_ITERATED) {
		if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
			char *p;
			for (p = tosay; p && *p; p++) {
				say_file("digits/%c.wav", *p);
			}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
			return SWITCH_STATUS_GENERR;
		}
		return SWITCH_STATUS_SUCCESS;
	}

	if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || 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) {
		snprintf(digits, sizeof(digits), "%10.10d", in);
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Say: %s \n", digits);
		switch (say_args->method) {
		case SSM_COUNTED:
			say_file("digits/ordinal.wav");
			/* Fall through */
		case SSM_PRONOUNCED:
			for (i = 0; i <= 9; i++) {
				switch (i) {
				case 0:
					/* Billions column */
					if (digits[i] != '0') {
						if (digits[i] != '1')
							say_file("digits/%c.wav", digits[i]);
						say_file("digits/10.wav");
					}
					break;
				case 1:
					/* Hundred millions columns */
					if (digits[i] != '0')
						say_file("digits/%c.wav", digits[i]);
					if (memcmp(digits, "00", 2) != 0)
						say_file("digits/100000000.wav");
					break;
				case 2:
					/* ten Millions column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						say_file("digits/10000000.wav");
					}
					break;
				case 3:
					/* Millions column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						say_file("digits/1000000.wav");
					}
					break;
				case 4:
					/* Hundred thousands column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						if (memcmp(digits + 2, "00000", 4) != 0)
							say_file("digits/100000.wav");
					}

					break;

				case 5:
					/* Ten thousands column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						if (memcmp(digits + 2, "0000", 4) != 0)
							say_file("digits/10000.wav");
					}
					break;
				case 6:
					/* Ten millions or thousands column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						say_file("digits/1000.wav");
					}
					break;
				case 7:
					/* hundreds column */
					if (digits[i] != '0') {
						say_file("digits/%c.wav", digits[i]);
						say_file("digits/100.wav");
					}
					break;
				case 8:
					/* Tens column */
					if (digits[i] != '0') {
						if (digits[i] == '2') {
							say_file("digits/20.wav");
							break;
						}
						if (digits[i] == '1') {
							say_file("digits/10.wav");
							break;
						}
						if (digits[i] != '1' || memcmp(digits, "00000000", 8) != 0) {
							say_file("digits/%c.wav", digits[i]);
						}
					}
					if (digits[8] != '0')
						say_file("digits/10.wav");
					break;
				case 9:
					/* Units column */
					if (digits[9] == '1') {
						if (digits[8] != '0') {
							say_file("digits/ed.wav", digits[i]);
						} else {
							say_file("digits/%c.wav", digits[i]);
						}
						break;
					}
					if (digits[9] != '0')
						say_file("digits/%c.wav", digits[i]);
					break;
				}
			}
			break;
		default:
			break;
		}
	} else {
		say_file("digits/0.wav");
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #24
0
static switch_status_t th_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int32_t t;
	switch_time_t target = 0;
	switch_time_exp_t tm;
#if 0
	switch_time_t this_morning;
	switch_time_exp_t tm2;
#endif
	uint8_t say_date = 0;
	uint8_t say_time = 0;

	if (say_args->type == SST_TIME_MEASUREMENT) {
		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 {
			if ((seconds = atoi(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

			if (seconds >= 60) {
				minutes = seconds / 60;
				r = seconds % 60;
				seconds = r;
			}

			if (minutes >= 60) {
				hours = minutes / 60;
				r = minutes % 60;
				minutes = r;
			}
		}

		if (hours) {
			if (hours == 2) {
				say_file("time/2s.wav");
			} else {
				say_num(hours, SSM_PRONOUNCED);
			}
			say_file("time/hours.wav");
		}
		if (minutes) {
			if (minutes == 2) {
				say_file("time/2s.wav");
			} else {
				say_num(minutes, SSM_PRONOUNCED);
			}
			say_file("time/minute.wav");
		} else {
			if (hours) {
				say_file("digits/0.wav");
				say_file("time/minute.wav");
			}
		}

		if (seconds) {
			if (seconds == 2) {
				say_file("time/2s.wav");
			} else {
				say_num(hours, SSM_PRONOUNCED);
			}
			say_file("time/seconds.wav");
		} else {
			if (hours || minutes) {
				say_file("digits/0.wav");
				say_file("time/second.wav");
			}
		}

		return SWITCH_STATUS_SUCCESS;
	}

	if ((t = atoi(tosay)) > 0)
		target = switch_time_make(t, 0);
	else
		target = switch_micro_time_now();
	switch_time_exp_lt(&tm, target);

	switch (say_args->type) {
	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;
	default:
		break;
	}

	if (say_date) {
		say_num(tm.tm_year + 1900, SSM_ITERATED);
		say_file("time/year.wav");
		say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
		say_file("time/month.wav");
		say_num(tm.tm_mday, SSM_PRONOUNCED);
		say_file("time/day.wav");
		say_file("time/day-%d.wav", tm.tm_wday);

#if 0
		tm = *localtime(&then);

		this_morning = switch_micro_time_now();
		switch_time_exp_lt(&tm2, this_morning);
		tm2->tm_hour = 0;
		tm2->tm_min = 0;
		tm2->tm_sec = 0;
		this_morning = mktime(tm2);

		if (this_morning <= then && then < (this_morning + 86400L)) {
			say_file("time/today.wav");
		} else if ((this_morning - 86400L) <= then && then < this_morning) {
			say_file("time/yesterday.wav");
		} else if ((this_morning + 86400L) <= then && then < (this_morning + 2 * 86400L)) {
			say_file("time/tomorrow.wav");
		} else if ((this_morning - 7 * 86400L) <= then && then < this_morning) {
			say_file("time/day-%d.wav", tm.tm_wday);
		} else {
			if (tm2->tm_year != tm.tm_year) {
				say_num(tm.tm_year + 1900, SSM_ITERATED);
				say_file("time/year.wav");
			}
			/*endif */
			if (tm2->tm_year != tm.tm_year || tm2->tm_mon != tm.tm_mon) {
				say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
				say_file("time/month.wav");
			}
			/*endif */
			/* Always say the day and the day of the week */
			say_num(tm.tm_mday, SSM_PRONOUNCED);
			say_file("time/day.wav");
			say_file("time/day-%d.wav", tm.tm_wday);
		}
#endif
	}

	if (say_time) {
		int32_t hour = tm.tm_hour;

		if (hour < 6) {
			say_file("time/morning.wav");
		} else if (hour < 12) {
			say_file("time/am.wav");
		} else if (tm.tm_hour < 18) {
			say_file("time/pm.wav");
		} else {
			say_file("time/evening.wav");
		}
		if (hour > 12)
			hour -= 12;
		if (hour == 0)
			hour = 12;

		if (hour == 2) {
			say_file("time/2s.wav");
		} else {
			say_num(hour, SSM_PRONOUNCED);
		}
		say_file("time/hour.wav");
		if (tm.tm_min == 2) {
			say_file("time/2s.wav");
		} else {
			say_num(tm.tm_min, SSM_PRONOUNCED);
		}
		say_file("time/minute.wav");
	}
	return SWITCH_STATUS_SUCCESS;
}
예제 #25
0
static switch_status_t hr_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int32_t t;
	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");
	
	int sat_desetinka = 0;
	int sat_jedinica = 0;
	int minuta_desetinka = 0;
	int minuta_jedinica = 0;
	int sekunda_desetinka = 0;
	int sekunda_jedinica = 0;

	if (say_args->type == SST_TIME_MEASUREMENT) {
		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 {
			if ((seconds = atol(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

			if (seconds >= 60) {
				minutes = seconds / 60;
				r = seconds % 60;
				seconds = r;
			}

			if (minutes >= 60) {
				hours = minutes / 60;
				r = minutes % 60;
				minutes = r;
			}
		}

		sat_jedinica = hours % 10;
		
		if (hours > 10)
			sat_desetinka = (int) (hours / 10);
	
		if (hours) 
		{
			say_num(hours, SSM_PRONOUNCED, "");
			
			if (sat_desetinka == 0 && sat_jedinica == 0)
			{
				nop;
			}
			else if (sat_desetinka == 1)
			{
				say_file("time/sati.wav");
			}
			else
			{
				switch(sat_jedinica)
				{
					case 1:
						say_file("time/sat.wav");
						break;
						
					case 2:
					case 3:
					case 4:
						say_file("time/sata.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_file("time/sati.wav");
						break;
				}
			}
		} 

		minuta_jedinica = minutes % 10;
		
		if (minutes > 10)
			minuta_desetinka = (int) (minutes / 10);
			
		if (minutes) 
		{
			
			
			if (minuta_desetinka == 1)
			{
				say_num(minutes, SSM_PRONOUNCED, "");
				say_file("time/minuta.wav");
			}
			else
			{
				switch(minuta_jedinica)
				{
					case 2:
						say_num(minutes, SSM_PRONOUNCED, "je");
						say_file("time/minute.wav");
						break;
						
					case 3:
					case 4:
						say_num(minutes, SSM_PRONOUNCED, "");
						say_file("time/minute.wav");
						break;
					
					case 1:
							say_num(minutes, SSM_PRONOUNCED, "a");
							say_file("time/minuta.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_num(minutes, SSM_PRONOUNCED, "");
						say_file("time/minuta.wav");
						break;
				}
			}
		} 

		sekunda_jedinica = seconds % 10;
		
		if (seconds > 10)
			sekunda_desetinka = (int) (seconds / 10);
			
		if (seconds) 
		{
			if (sekunda_desetinka == 1)
			{
				say_num(seconds, SSM_PRONOUNCED, "");
				say_file("time/sekundi.wav");
			}
			else if (sekunda_desetinka == 0)
			{
				switch(sekunda_jedinica)
				{
					case 1:
						say_num(seconds, SSM_PRONOUNCED, "a");
						say_file("time/sekunda.wav");
						break;
						
					case 2:
						say_num(seconds, SSM_PRONOUNCED, "je");
						say_file("time/sekunde.wav");
						break;
						
					case 3:
					case 4:
						say_num(seconds, SSM_PRONOUNCED, "");
						say_file("time/sekunde.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_file("time/sekundi.wav");
						break;
				}
			}
			else
			{
				switch(sekunda_jedinica)
				{
					case 1:
						say_num(seconds, SSM_PRONOUNCED, "a");
						say_file("time/sekunda.wav");
						break;
						
					case 2:
						say_num(seconds, SSM_PRONOUNCED, "je");
						say_file("time/sekunde.wav");
						break;
						
					case 3:
					case 4:
						say_num(seconds, SSM_PRONOUNCED, "");
						say_file("time/sekunde.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_num(seconds, SSM_PRONOUNCED, "");
						say_file("time/sekundi.wav");
						break;
				}
			}
		} 

		return SWITCH_STATUS_SUCCESS;
	}

	if ((t = atol(tosay)) > 0) {
		target = switch_time_make(t, 0);
		target_now = switch_micro_time_now();
	} else {
		target = switch_micro_time_now();
		target_now = switch_micro_time_now();
	}

	if (tz) {
		int check = atoi(tz);
		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]\n", 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);
	}

	switch (say_args->type) {
	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;
	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:
		break;
	}

	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);
	}

	if (say_date) {
		say_year = say_month = say_day = say_dow = 1;
		say_today = say_yesterday = 0;
	}

	if (say_day) {
		say_num(tm.tm_mday, SSM_COUNTED, "");
	}
	
	if (say_month) {
		say_file("time/mon-%d.wav", tm.tm_mon);
	}
	
	if (say_year) {
		int y = tm.tm_year + 1900;
		int tis = 0;
		
		//say_num(tm.tm_year + 1900, SSM_PRONOUNCED, "");
		//1 - 99 => h-1a.wav - h-99a.wav
		if (y >= 1 && y <= 99)
		{
			say_file("digits/h-%da.wav", y);
		}
		// [1-9]00            =>     h-[1-9]00a.wav
		else if (y >= 100 && y <= 900 && y % 100 == 0)
		{
			say_file("digits/h-%da.wav", y);
		}
		//[1-9]01 - [1-9]99    =>     [1-9]00.wav  + (h-1a.wav - h-99a.wav)
		else if (y >= 100 && y <= 900 && y % 100 != 0)
		{
			say_file("digits/h-%da.wav", (int) y - (y % 100));
			say_file("digits/h-%da.wav", (int) y % 100);
		}
		// 1000 => thousand-ta.wav
		else if (y == 1000)
		{
			say_file("digits/thousand-ta.wav");
		}
		// 1001 - 1999 => thousand-u.wav + [1-9]00.wav + (h-1a.wav - h-99a.wav)
		else if (y >= 1001 && y <= 1999)
		{
			say_file("digits/thousand-u.wav");
			if (0 != (int) ((y - 1000) - ((y - 1000) % 100)))
				say_file("digits/h-%da.wav", (int) ((y - 1000) - ((y - 1000) % 100)));
				
			say_file("digits/h-%da.wav", (int) y % 100);
		}
		//2000  => 2je.wav + thousand-ta.wav
		else if (y == 2000)
		{
			say_file("digits/2je.wav");
			say_file("digits/thousand-ta.wav");
		}
		// 2001 - 2999 => 2je.wav + thousands-e.wav + [1-9]00.wav + (h-1a.wav - h-99a.wav)
		else if (y >= 2001 && y <= 2999)
		{
			say_file("digits/2je.wav");
			say_file("digits/thousands-e.wav");
			if (0 != (int) ((y - 2000) - ((y - 2000) % 100)))
				say_file("digits/h-%da.wav", (int) ((y - 2000) - ((y - 2000) % 100)));
				
			say_file("digits/h-%da.wav", (int) y % 100);
		}
		// 3000 => [3-9].wav + thousand-ta.wav
		else if (y >= 3000 && y <= 9000 && y % 1000 == 0)
		{
			say_file("digits/%d.wav", (int) (y / 1000));
			say_file("digits/thousand-ta.wav");
		}
		// [3-9]001 - [3-9]999 => [3-9].wav + thousands-e.wav + [1-9]00.wav + (h-1a.wav - h-99a.wav)
		else if (y >= 3000 && y <= 9000 && y % 1000 != 0)
		{
			say_file("digits/%d.wav", (int) (y / 1000));
			say_file("digits/thousands-e.wav");
			tis = y  - (y % 1000);
			if (0 != (int) ((y - tis) - ((y - tis) % 100)))
				say_file("digits/h-%da.wav",  (int) ((y - tis) - ((y - tis) % 100)));
				
			say_file("digits/h-%da.wav", (int) y % 100);
		}
		
		//say_num(tm.tm_year + 1900, SSM_COUNTED, "a");
	}

	
	if (say_time) 
	{
		say_num(tm.tm_hour, SSM_PRONOUNCED, "");
		
		sat_jedinica = tm.tm_hour % 10;
		
		if (tm.tm_hour >= 10)
			sat_desetinka = (int) (tm.tm_hour / 10);
			
	
		if (tm.tm_hour) 
		{
			if (sat_desetinka == 0 && sat_jedinica == 0)
			{
				nop;
			}
			else if (sat_desetinka == 1)
			{
				say_file("time/sati.wav");
			}
			else
			{
				switch(sat_jedinica)
				{
					case 1:
						say_file("time/sat.wav");
						break;
						
					case 2:
					case 3:
					case 4:
						say_file("time/sata.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_file("time/sati.wav");
						break;
					
				}
			}
		} 
		
		minuta_jedinica = tm.tm_min % 10;
		
		if (tm.tm_min >= 10)
			minuta_desetinka = (int) (tm.tm_min / 10);
			
		if (tm.tm_min) 
		{
			if (minuta_desetinka == 1)
			{
				say_num(tm.tm_min, SSM_PRONOUNCED, "");
				say_file("time/minuta.wav");
			}
			else
			{
				switch(minuta_jedinica)
				{
					case 2:
						say_num(tm.tm_min, SSM_PRONOUNCED, "je");
						say_file("time/minute.wav");
						break;
						
					case 3:
					case 4:
						say_num(tm.tm_min, SSM_PRONOUNCED, "");
						say_file("time/minute.wav");
						break;
					
					case 1:
						say_num(tm.tm_min, SSM_PRONOUNCED, "a");
						say_file("time/minuta.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_num(tm.tm_min, SSM_PRONOUNCED, "");
						say_file("time/minuta.wav");
						break;
				}
			}
		} 
		
		sekunda_jedinica = tm.tm_sec % 10;
		
		if (tm.tm_sec >= 10)
			sekunda_desetinka = (int) (tm.tm_sec / 10);
			
		if (tm.tm_sec) 
		{
			if (sekunda_desetinka == 1)
			{
				say_num(tm.tm_sec, SSM_PRONOUNCED, "");
				say_file("time/sekundi.wav");
			}
			else if (sekunda_desetinka == 0)
			{
				switch(sekunda_jedinica)
				{
					case 1:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "a");
						say_file("time/sekunda.wav");
						break;
						
					case 2:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "je");
						say_file("time/sekunde.wav");
						break;
						
					case 3:
					case 4:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "");
						say_file("time/sekunde.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_file("time/sekundi.wav");
						break;
				}
			}
			else
			{
				switch(sekunda_jedinica)
				{
					case 1:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "a");
						say_file("time/sekunda.wav");
						break;
						
					case 2:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "je");
						say_file("time/sekunde.wav");
						break;
						
					case 3:
					case 4:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "");
						say_file("time/sekunde.wav");
						break;
						
					case 0:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						say_num(tm.tm_sec, SSM_PRONOUNCED, "");
						say_file("time/sekundi.wav");
						break;
				}
			}
		} 
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #26
0
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)
{

	/*a => 1xx-9xx*/
	if (a) {
		switch (a) {
		case 1:
			if (b || c) {
				say_file("digits/hundred.wav");
			} else {
				say_file("digits/100.wav");
			}
			break;
		case 2:
			say_file("digits/200.wav");
			break;
		case 3:
			say_file("digits/300.wav");
			break;
		case 5:
			say_file("digits/500.wav");
			break;
		default:
			say_file("digits/%d.wav", a);
			say_file("digits/hundreds.wav");
			break;
		}
		if (b || c) {
			say_file("currency/and.wav");
		}
	}
	/* b => 1x - 9x */
	if (b) {
		if (b > 1) {
			if (method == SSM_COUNTED) {
				say_file("digits/h-%d0.wav", b);
			} else {
				say_file("digits/%d0.wav", b);
				if (c > 0) {
					say_file("currency/and.wav");
				}
			}
		} else {
			say_file("digits/%d%d.wav", b, c);
			c = 0;
		}
	}
	/* c => 0 - 9*/
	if (c) {
		if (method == SSM_COUNTED) {
			say_file("digits/h-%d.wav", c);
		} else {
			say_file("digits/%d.wav", c);
		}
	}

	if (what && (a || b || c)) {
		say_file(what);
	}

	return SWITCH_STATUS_SUCCESS;
}
예제 #27
0
static switch_status_t fa_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	int32_t t;
	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");
	int jalali_year = 1, jalali_month = 0, jalali_day = 0;

	if (say_args->type == SST_TIME_MEASUREMENT) {
		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 {
			if ((seconds = atol(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

			if (seconds >= 60) {
				minutes = seconds / 60;
				r = seconds % 60;
				seconds = r;
			}

			if (minutes >= 60) {
				hours = minutes / 60;
				r = minutes % 60;
				minutes = r;
			}
		}

		if (hours) {
			say_num(hours, SSM_PRONOUNCED);
			if(minutes || seconds)
			{
				say_file("time/hour+.wav");
			}
			else
				say_file("time/hour.wav");
		}

		if (minutes) {
			say_num(minutes, SSM_PRONOUNCED);
			if( seconds )
			{
				say_file("time/minutes+.wav");
			}
			else
				say_file("time/minutes.wav");
		}

		if (seconds) {
			say_num(seconds, SSM_PRONOUNCED);
			say_file("time/seconds.wav");
		}

		return SWITCH_STATUS_SUCCESS;
	}

	if ((t = atol(tosay)) > 0) {
		target = switch_time_make(t, 0);
		target_now = switch_micro_time_now();
	} else {
		target = switch_micro_time_now();
		target_now = switch_micro_time_now();
	}

	if (tz) {
		int check = atoi(tz);
		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]\n", 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);
	}

	switch (say_args->type) {
	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;
	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:
		break;
	}

	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);
	}

	if (say_date) {
		say_year = say_month = say_day = say_dow = 1;
		say_today = say_yesterday = 0;
	}

	gregorian_to_jalali(&jalali_year,&jalali_month,&jalali_day,tm.tm_year + 1900,tm.tm_mon + 1,tm.tm_mday);

	if (say_day) {
		if(jalali_day > 20 && jalali_day != 30)
		{
			say_file("digits/%d+.wav", (jalali_day - jalali_day % 10));
			say_file("digits/%de.wav", jalali_day % 10);
		}
		else
			say_file("digits/%de.wav", jalali_day);
	}

	if (say_month) {
		say_file("time/mon-%d.wav", jalali_month - 1);
	}

	if (say_year) {
		say_num(jalali_year, SSM_PRONOUNCED);
	}

	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");
		}

		if (hour > 12) {
			hour -= 12;
			pm = 1;
		} else if (hour == 12) {
			pm = 1;
		} else if (hour == 0) {
			hour = 12;
			pm = 0;
		}

		say_file("time/hour-e.wav");
		say_file("digits/%do.wav",hour);
		play_group(SSM_PRONOUNCED, 0, (tm.tm_min - tm.tm_min % 10) / 10, tm.tm_min % 10, "time/minutes-e.wav", session, args);
		say_file("time/%s.wav", pm ? "p-m" : "a-m");
	}

	return SWITCH_STATUS_SUCCESS;
}