Exemple #1
0
static switch_status_t pl_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
{
	int in;
	int x = 0;
	int places[9] = { 0 };
	char sbuf[128] = "";
	switch_status_t status;

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "SAY: %s\n", tosay);

	if (say_args->method == SSM_ITERATED) {
		if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
			char *p;
			for (p = tosay; p && *p; p++) {
				switch_say_file(sh, "digits/%c", *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) {
		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/1000000", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(SSM_PRONOUNCED, say_args->gender, places[5], places[4], places[3], "digits/1000", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(say_args->method, say_args->gender, places[2], places[1], places[0], NULL, sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			break;
		default:
			break;
		}
	} else {
		switch_say_file(sh, "digits/0");
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #2
0
static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_say_file_handle_t *sh)
{

	if (a) {
		switch_say_file(sh, "digits/%d", a);
		switch_say_file(sh, "digits/hundred");
	}

	if (b) {
		if (b > 1) {
			if ((c == 0) && (method == SSM_COUNTED)) {
				switch_say_file(sh, "digits/h-%d0", b);
			} else {
				switch_say_file(sh, "digits/%d0", b);
			}
		} else {
			switch_say_file(sh, "digits/%d%d", b, c);
			c = 0;
		}
	}

	if (c) {
		if (method == SSM_COUNTED) {
			switch_say_file(sh, "digits/h-%d", c);
		} else {
			switch_say_file(sh, "digits/%d", c);
		}
	}

	if (what && (a || b || c)) {
		switch_say_file(sh, what);
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #3
0
static switch_status_t pl_say_ip(switch_say_file_handle_t *sh,
							  char *tosay,
							  switch_say_args_t *say_args)
	
{
	char *a, *b, *c, *d;
	switch_status_t status = SWITCH_STATUS_FALSE;
	
	if (!(a = strdup(tosay))) {
		abort();
	}

	if (!(b = strchr(a, '.'))) {
		goto end;
	}

	*b++ = '\0';

	if (!(c = strchr(b, '.'))) {
		goto end;
	}

	*c++ = '\0';

	if (!(d = strchr(c, '.'))) {
		goto end;
	}

	*d++ = '\0';

	say_num(sh, atoi(a), say_args->method, SSG_MASCULINE);
	switch_say_file(sh, "digits/dot");
	say_num(sh, atoi(b), say_args->method, SSG_MASCULINE);
	switch_say_file(sh, "digits/dot");
	say_num(sh, atoi(c), say_args->method, SSG_MASCULINE);
	switch_say_file(sh, "digits/dot");
	say_num(sh, atoi(d), say_args->method, SSG_MASCULINE);

 end:
	
	free(a);

	return status;
}
Exemple #4
0
static switch_status_t ru_say_spell(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt)
{
        char *p;

        for (p = tosay; p && *p; p++) {
                int a = tolower((int) *p);
                if (a >= '0' && a <= '9') {
                        switch_say_file(sh, "digits/%c", a);
                } else {
                        if (say_args->type == SST_NAME_SPELLED) {
                                switch_say_file(sh, "ascii/%d", a);
                        } else if (say_args->type == SST_NAME_PHONETIC) {
                                switch_say_file(sh, "phonetic-ascii/%d", a);
                        }
                }
        }

        return SWITCH_STATUS_SUCCESS;
}
Exemple #5
0
static switch_status_t ru_ip(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt)
{
	char *a, *b, *c, *d;
	switch_status_t status = SWITCH_STATUS_FALSE;
	if (!(a = strdup(tosay))) {
    		abort();
//		return SWITCH_STATUS_FALSE;
	}

	if (!(b = strchr(a, '.'))) {
		goto end;
	}

	*b++ = '\0';

	if (!(c = strchr(b, '.'))) {
		 goto end;
	}

	*c++ = '\0';

	if (!(d = strchr(c, '.'))) {
		 goto end;
	}

	*d++ = '\0';

	ru_say_count(sh, a, male, nominativus);
	switch_say_file(sh, "digits/dot");

	ru_say_count(sh, b, male, nominativus);
	switch_say_file(sh, "digits/dot");

	ru_say_count(sh, c, male, nominativus);
	switch_say_file(sh, "digits/dot");

	ru_say_count(sh, d, male, nominativus);
end:
	free(a);
	return status;
}
Exemple #6
0
static switch_status_t say_telephone_number(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
{
	int silence = 0;
	char *p;

	for (p = tosay; !zstr(p); p++) {
		int a = tolower((int) *p);
		if (a >= '0' && a <= '9') {
			switch_say_file(sh, "digits/%c", a);
			silence = 0;
		} else if (a == '+' || (a >= 'a' && a <= 'z')) {
			switch_say_file(sh, "ascii/%d", a);
			silence = 0;
		} else if (!silence) {
			switch_say_file(sh, "silence_stream://100");
			silence = 1;
		}
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #7
0
static switch_status_t en_say_money(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args, char *main_currency_file_single, char *main_currency_file_plural, char *fractional_currency_file_single, char *fractional_currency_file_plural)
{
	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] == '-') {
		switch_say_file(sh, "currency/negative");
		dollars++;
	}

	/* Say dollar amount */
	en_say_general_count(sh, dollars, say_args);
	if (atoi(dollars) == 1) {
		switch_say_file(sh, main_currency_file_single);
	} else {
		switch_say_file(sh, main_currency_file_plural);
	}
	

	/* Say cents */
	if (cents) {
		/* Say "and" */
		switch_say_file(sh, "currency/and");

		en_say_general_count(sh, cents, say_args);
		if (atoi(cents) == 1) {
			switch_say_file(sh, fractional_currency_file_single);
		} else {
			switch_say_file(sh, fractional_currency_file_plural);
		}
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #8
0
//дописать
static switch_status_t ru_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt)
{
	switch_status_t status;
	cases_t cases;				//падеж
	say_gender_t gender;		//тип произношения
	char sbuf[128] = "";

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

	switch (say_args->type) {
	case SST_MESSAGES:
		gender = it;
		cases = nominativus;
		break;
	default:
		gender = male;
		cases = nominativus;
		if (say_opt->gender>0) {
		    gender=say_opt->gender;
//		    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " opt_gender=%d type=%d   cases=%d\n", gender, cases,say_opt->gender);
		}
		if (say_opt->cases>0) {
		    cases=say_opt->cases;
//		    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " opt_gender=%d type=%d   cases=%d\n", gender, cases,say_opt->gender);

		}
		break;
	};
	//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " opt_gender=%d type=%d   cases=%d\n", gender, cases,say_opt->gender);
	status = ru_say_count(sh, tosay, (say_gender_t)gender, (cases_t)cases);
	return status;
}
Exemple #9
0
static switch_status_t play_group(say_gender_t gender, cases_t cases, int a, int b, int c, unit_t what,	switch_say_file_handle_t *sh)
{
//	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play_group ! %d%d%d  gender=%d  causes=%d\n",a,b,c,gender,cases);
	if (a) {
		if (((b == 0) && (c == 0)) || (matrix[cases][gender].all == 1)) {	//если b и с равны 0 то сказать шестьсот, сестисотый, шестисотая
			if (what == million) {	//префикс           число          окончание
				switch_say_file(sh, "digits/%s%d00%s", matrix[cases][gender].million[12], a, matrix[cases][gender].million[13]);
				switch_say_file(sh, "digits/%s", matrix[cases][gender].million[11]);
			} else if (what == thousand) {
				switch_say_file(sh, "digits/%s%d00%s", matrix[cases][gender].thousand[12], a, matrix[cases][gender].thousand[13]);
				switch_say_file(sh, "digits/%s", matrix[cases][gender].thousand[11]);
			} else {
				switch_say_file(sh, "digits/%s%d00%s", matrix[cases][gender].num[6], a, matrix[cases][gender].num[7]);
			}
		} else {				//если дальше есть цифры то тысячи и миллионы не прозносить пока
			switch_say_file(sh, "digits/%d00", a);
		}
	}

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

	if (c || what == zero) {
		if (c <= 5) {
			if (what == million) {
				if ((strlen(matrix[cases][gender].million[c * 2])) > 0) {	// не произносить если не заданно например 1 миллион а просто миллион
					switch_say_file(sh, "digits/%s", matrix[cases][gender].million[c * 2]);
				}
				switch_say_file(sh, "digits/%s", matrix[cases][gender].million[c * 2 + 1]);
			} else if (what == thousand) {
				if ((strlen(matrix[cases][gender].thousand[c * 2])) > 0) {	// не произносить если не заданно например одна тысячас  а просто тысяча
					switch_say_file(sh, "digits/%s", matrix[cases][gender].thousand[c * 2]);
				}
				switch_say_file(sh, "digits/%s", matrix[cases][gender].thousand[c * 2 + 1]);
			} else {			//просто произнести цифры с префиксом и окончанием
				switch_say_file(sh, "digits/%s", matrix[cases][gender].num[c]);
			}
		} else {				/* больше 5 */

			if (what == million) {
				switch_say_file(sh, "digits/%s%d%s", matrix[cases][gender].million[12], c, matrix[cases][gender].million[13]);
				switch_say_file(sh, "digits/%s", matrix[cases][gender].million[11]);
			} else if (what == thousand) {
				switch_say_file(sh, "digits/%s%d%s", matrix[cases][gender].thousand[12], c, matrix[cases][gender].thousand[13]);
				switch_say_file(sh, "digits/%s", matrix[cases][gender].thousand[11]);
			} else {			//просто произнести цифры с префиксом и окончанием
				switch_say_file(sh, "digits/%s%d%s", matrix[cases][gender].num[6], c, matrix[cases][gender].num[7]);
			}
		}
	}
	return SWITCH_STATUS_SUCCESS;
}
Exemple #10
0
static switch_status_t ru_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt)
{
	int32_t t;
	char buf[80];
	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;
	const char *tz = NULL;
	tz = switch_say_file_handle_get_variable(sh, "timezone");    

	//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_time %s  type=%d method=%d\n", tosay, say_args->type, say_args->method);

	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 = strdup(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);
				}
			}
			free(tme);
		} else {
			if ((seconds = atol(tosay)) <= 0) {
				seconds = (int64_t) switch_epoch_time_now(NULL);
			}

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

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

		switch_snprintf(buf, sizeof(buf), "%u", (unsigned) hours);
		ru_say_count(sh, buf, male, nominativus);

		if (((hours % 10) == 1) && (hours != 11)) {
			/* час */
			switch_say_file(sh, "time/hour");
		} else if (((hours % 10 > 1) && (hours % 10 < 5)) && ((hours < 12) || (hours > 14))) {
			switch_say_file(sh, "time/hours-a");	/* часа */
		} else {
			switch_say_file(sh, "time/hours");	/* часов */
		}

		switch_snprintf(buf, sizeof(buf), "%u", (unsigned) minutes);	//перевести минуты в *char
		ru_say_count(sh, buf, female, nominativus);

		if (((minutes % 10) == 1) && (minutes != 11)) {
			switch_say_file(sh, "time/minute");	//минута
		} else if (((minutes % 10 > 1) && (minutes % 10 < 5)) && ((minutes < 12) || (minutes > 14))) {
			switch_say_file(sh, "time/minutes-i");	// минуты
		} else {
			switch_say_file(sh, "time/minutes");	//минут
		}

		if (seconds != 0) {
			switch_snprintf(buf, sizeof(buf), "%u", (unsigned) seconds);
			ru_say_count(sh, buf, female, nominativus);
			if (((seconds % 10) == 1) && (seconds != 11)) {
				switch_say_file(sh, "time/second");	// секунда
			} else if (((seconds % 10 > 1) && (seconds % 10 < 5)) && ((seconds < 12) || (seconds > 14))) {
				switch_say_file(sh, "time/seconds-i");	// секуны
			} else {
				switch_say_file(sh, "time/seconds");	//секунд
			}
		}
		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_LOG, 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;
		tm.tm_sec = 0; // В коротком варианте секунды не проговариваем
		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) {
		switch_say_file(sh, "time/today");
	}
	if (say_yesterday) {
		switch_say_file(sh, "time/yesterday");
	}
	if (say_dow) {
		switch_say_file(sh, "time/day-%d", tm.tm_wday);
	}
	if (say_date) {
		say_year = say_month = say_day = say_dow = 1;
		say_today = say_yesterday = 0;
	}
	if (say_day) {
		switch_snprintf(buf, sizeof(buf), "%u", (unsigned) tm.tm_mday);
		ru_say_count(sh, buf, male_h, genitivus);
	}
	if (say_month) {
		switch_say_file(sh, "time/mon-%d", tm.tm_mon);
	}
	if (say_year) {
		switch_snprintf(buf, sizeof(buf), "%u", (unsigned) (tm.tm_year + 1900));
		ru_say_count(sh, buf, male_h, genitivus);
		switch_say_file(sh, "time/h-year");
	}
	if (say_time) {
		if (say_month || say_year || say_date || say_dow) {
			switch_say_file(sh, "time/at");
		}
		switch_snprintf(buf, sizeof(buf), "%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
		say_args->type = SST_TIME_MEASUREMENT;
		ru_say_time(sh, buf, say_args,say_opt);
	}
	return SWITCH_STATUS_SUCCESS;
}
Exemple #11
0
static switch_status_t ru_say_money(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt)
{
	char sbuf[16] = "";
	char *rubles = NULL;
	char *kopecks = NULL;
	int irubles = 0;
	int iruble = 0;
	int ikopecks = 0;
	int ikopeck = 0;
//	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s say_opt->currency=%d\n", tosay,say_opt->currency);

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

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

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

	if (sbuf[0] == '-') {
		switch_say_file(sh, "currency/minus");
		rubles++;
	}


	ru_say_count(sh, rubles, matrix_currency[say_opt->currency].first_gender,matrix_currency[say_opt->currency].first_cases);

	if (rubles) {
		irubles = atoi(rubles) % 100;
		iruble = atoi(rubles) % 10;
	}
	if (iruble<5) {
	    if ((irubles>10)&&(irubles<15)) {
		switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].first[5]);
	    }
	    else {
		switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].first[iruble]);
	    }
	}
	else {
	    switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].first[5]);
	}
	    
	    
	/* Say kopecks */
	ru_say_count(sh, kopecks, matrix_currency[say_opt->currency].second_gender,matrix_currency[say_opt->currency].second_cases);

	if (kopecks) {
		ikopecks = atoi(kopecks) % 100;
		ikopeck = atoi(kopecks) % 10;
	}

	if (ikopeck<5) {
	    if ((ikopecks>10)&&(ikopecks<15)) {
		switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].second[5]);
	    }
	    else {
    		switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].second[ikopeck]);
	    }
	}
	else {
	    switch_say_file(sh, "currency/%s",matrix_currency[say_opt->currency].second[5]);
	}



	return SWITCH_STATUS_SUCCESS;
}
Exemple #12
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_say_file_handle_t *sh)
{
	char tmp[80];

	if (a) {
		switch_say_file(sh, "digits/%d00", a);
	}

	if (b) {
		if (b > 1) {
			if (method == SSM_COUNTED) {
				if (gender == SSG_MASCULINE)
					switch_say_file(sh, "digits/%d0_pm", b);
				else if (gender == SSG_FEMININE)
					switch_say_file(sh, "digits/%d0_pf", b);
				else if (gender == SSG_NEUTER)
					switch_say_file(sh, "digits/%d0_pn", b);
			} else {
				switch_say_file(sh, "digits/%d0", b);
			}
		} else {
			if (method == SSM_COUNTED) {
				if (gender == SSG_MASCULINE)
					switch_say_file(sh, "digits/%d%d_pm", b, c);
				else if (gender == SSG_FEMININE)
					switch_say_file(sh, "digits/%d%d_pf", b, c);
				else if (gender == SSG_NEUTER)
					switch_say_file(sh, "digits/%d%d_pn", b, c);
			} else {
				switch_say_file(sh, "digits/%d%d", b, c);
			}
			c = 0;
		}
	}

	if (c) {
		if (method == SSM_COUNTED) {
			if (gender == SSG_MASCULINE && b != 1  && (c == 1 || c == 2)) {
				switch_say_file(sh, "digits/%d_pm", c);
			} else if (gender == SSG_FEMININE && b != 1  && (c == 1 || c == 2)) {
				switch_say_file(sh, "digits/%d_pf", c);
			} else {
				switch_say_file(sh, "digits/%d_pn", c);
			}
		} else {
			if (gender == SSG_FEMININE && b != 1  && (c == 1 || c == 2)) {
				switch_say_file(sh, "digits/%d_f", c);
			} else {
				switch_say_file(sh, "digits/%d", c);
			}
		}
	}

	if (what && (a || b || c)) {
		if (!a && !b && c == 1) {
			switch_snprintf(tmp, sizeof(tmp), "%s", what);
		} else if (b != 1 && (c == 2 || c == 3 || c == 4)) {
			switch_snprintf(tmp, sizeof(tmp), "%sa", what);
		} else if (a*100+b*10+c > 4) {
			switch_snprintf(tmp, sizeof(tmp), "%ss", what);
		}
		switch_say_file(sh, tmp);
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #13
0
static switch_status_t pl_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_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;
	const char *tz = NULL;

	tz = switch_say_file_handle_get_variable(sh, "timezone");

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "SAY: %s\n", tosay);

	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 = strdup(tosay);
			char *p;

			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse time string!\n");
			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);
				}
			}
			free(tme);
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse time in seconds!\n");
			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) {
			int hd = 0, hj = 0;
			say_num(sh, hours, SSM_PRONOUNCED, SSG_FEMININE);
			hj = hours % 10;
			hd = (hours/10) % 10;
			if (hours == 1) {
				switch_say_file(sh, "time/t_godzina");
			}else if (hd != 1 && ( hj == 2 || hj == 3 || hj == 4)) {
				switch_say_file(sh, "time/t_godziny");
			} else {
				switch_say_file(sh, "time/t_godzin");
			}
		} else {
			switch_say_file(sh, "digits/0");
			switch_say_file(sh, "time/t_godzin");
		}

		if (minutes) {
			int md = 0, mj = 0;
			say_num(sh, minutes, SSM_PRONOUNCED, SSG_FEMININE);
			mj = minutes % 10;
			md = (minutes/10) % 10;
			if (minutes == 1) {
				switch_say_file(sh, "time/minuta");
			}else if (md != 1 && ( mj == 2 || mj == 3 || mj == 4)) {
				switch_say_file(sh, "time/t_minuty");
			} else {
				switch_say_file(sh, "time/t_minut");
			}
		} else {
			switch_say_file(sh, "digits/0");
			switch_say_file(sh, "time/t_minut");
		}

		if (seconds) {
			int sd = 0, sj = 0;
			say_num(sh, seconds, SSM_PRONOUNCED, SSG_FEMININE);
			sj = seconds % 10;
			sd = (seconds/10) % 10;
			if (seconds == 1) {
				switch_say_file(sh, "time/t_sekunda");
			}else if (sd != 1 && ( sj == 2 || sj == 3 || sj == 4)) {
				switch_say_file(sh, "time/t_sekundy");
			} else {
				switch_say_file(sh, "time/t_sekund");
			}
		} else {
			switch_say_file(sh, "digits/0");
			switch_say_file(sh, "time/t_sekund");
		}

		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_LOG, 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) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SAY: today\n");
		switch_say_file(sh, "time/t_dzisiaj");
	}
	if (say_yesterday) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SAY: yesterday\n");
		switch_say_file(sh, "time/t_wczoraj");
	}
	if (say_dow) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SAY: dow\n");
		switch_say_file(sh, "time/day-%d", tm.tm_wday);
	}

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

	if (say_day) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SAY: day\n");
		//say_num(sh, tm.tm_mday, SSM_COUNTED, SSG_MASCULINE);
		switch_say_file(sh, "digits/%02d_pm", tm.tm_mday);
	}
	if (say_month) {
		switch_say_file(sh, "time/mon-%d_D", tm.tm_mon);
	}
	if (say_year) {
		say_num(sh, tm.tm_year + 1900, SSM_COUNTED, SSG_MASCULINE);
		//switch_say_file(sh, "time/t_roku");
	}

	if (say_time) {
		switch_say_file(sh, "time/t_godzina");
		say_num(sh, tm.tm_hour, SSM_COUNTED, SSG_FEMININE);
		//switch_say_file(sh, "digits/%da", tm.tm_hour);

		say_num(sh, tm.tm_min, SSM_PRONOUNCED, SSG_FEMININE);
		/* switch_say_file(sh, "digits/t_minut");*/
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #14
0
static switch_status_t sin_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_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;
	const char *tz = NULL;

	tz = switch_say_file_handle_get_variable(sh, "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 = strdup(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);
				}
			}
			free(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) {
			
			if (hours == 1) {
				switch_say_file(sh, "time/payai");
			} else {
				switch_say_file(sh, "time/paya");
				say_num(sh, hours, SSM_PRONOUNCED);
			}
			
		} else {
			/*switch_say_file(sh, "time/s_hours");
			switch_say_file(sh, "digits/s_i-0");
	*/		
		}

		if (minutes) {
			
			if (minutes == 1) {
				switch_say_file(sh, "time/winadiyai");
			} else {
				switch_say_file(sh, "time/winadi");
				say_num(sh, minutes, SSM_PRONOUNCED);
			}
			
		} else {
			/*switch_say_file(sh, "time/s_minutes");
			switch_say_file(sh, "digits/s_i-0");*/
			
		}

		if (seconds) {
			
			if (seconds == 1) {
				switch_say_file(sh, "time/thathparayai");
			} else {
				switch_say_file(sh, "time/thathpara");
				say_num(sh, seconds, SSM_PRONOUNCED);
			}
			
		} else {
			
		/*	switch_say_file(sh, "time/s_seconds");
			switch_say_file(sh, "digits/s_i-0");*/
		}

		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_LOG, 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) {
		switch_say_file(sh, "time/today");
	}
	if (say_yesterday) {
		switch_say_file(sh, "time/yesterday");
	}
	if (say_dow) {
		switch_say_file(sh, "time/day-s_%d", tm.tm_wday);
	}

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

	if (say_month) {
		switch_say_file(sh, "time/mon-s_%d", tm.tm_mon);
	}
	if (say_day) {
		say_num(sh, tm.tm_mday, SSM_COUNTED);
	}
	if (say_year) {
		say_num(sh, tm.tm_year + 1900, SSM_PRONOUNCED_YEAR);
	}

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

		if (say_date || say_today || say_yesterday || say_dow) {
			switch_say_file(sh, "time/at");
		}

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

		say_num(sh, hour, SSM_PRONOUNCED);

		if (tm.tm_min > 9) {
			say_num(sh, tm.tm_min, SSM_PRONOUNCED);
		} else if (tm.tm_min) {
			switch_say_file(sh, "time/oh");
			say_num(sh, tm.tm_min, SSM_PRONOUNCED);
		} else {
			switch_say_file(sh, "time/oclock");
		}

		switch_say_file(sh, "time/%s", pm ? "p-m" : "a-m");
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #15
0
static switch_status_t sin_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_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++) {
				switch_say_file(sh, "digits/%c", *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) {
		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_PRONOUNCED_YEAR:
			{
				int num = atoi(tosay);
				int a = num / 100;
				int b = num % 100;

				if (!b || !(a % 10)) {
					say_num(sh, num, SSM_PRONOUNCED);
					return SWITCH_STATUS_SUCCESS;
				}

				say_num(sh, a, SSM_PRONOUNCED);
				say_num(sh, b, SSM_PRONOUNCED);

				return SWITCH_STATUS_SUCCESS;
			}
			break;
		case SSM_COUNTED:
		case SSM_PRONOUNCED:
			if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/s_million", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}

			if(places[2] == 0 &&  places[1]  == 0  && places[0] == 0)
			{
				if ((status = play_group1(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/s_i-thousand", sh)) != SWITCH_STATUS_SUCCESS) {
					return status;
				}
			}
			else
			{
				if ((status = play_group1(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/s_k-thousand", sh)) != SWITCH_STATUS_SUCCESS) {
					return status;
				}
			}


			if ((status = play_group2(say_args->method, places[2], places[1], places[0], NULL, sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			break;
		default:
			break;
		}
	} else {
		switch_say_file(sh, "digits/0");
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #16
0
static switch_status_t vi_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
{
	double in;
	//int in;
	int x = 0;
	int places[12] = { 0 };
	char sbuf[128] = "";
	char *f1,*f2;
	int fi1;
	
	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++) {
				switch_say_file(sh, "digits/%c", *p);
			}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
			return SWITCH_STATUS_GENERR;
		}
		return SWITCH_STATUS_SUCCESS;
	}

	//Xu ly cac so co phan thap phan
	if (!(f1 = strdup(tosay))) {
		abort();
	}
   f2 = strchr(f1, '.');
   if(f2)
   {
	*f2++ = '\0';
	fi1= atoi(f1);
	//itoa(fi1,tosay,10);
	sprintf(tosay, "%d", fi1);
   }
	if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || strlen(tosay) > 12) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	//in = atoi(tosay);
	in = atof(tosay);

	if (in != 0) {
		for (x = 12; x >= 0; x--) {
			double num = (double) pow(10, 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_PRONOUNCED_YEAR:
			{
				int num = atoi(tosay);
				int a = num / 100;
				int b = num % 100;

				if (!b || !(a % 10)) {
					say_num(sh, num, SSM_PRONOUNCED);
					return SWITCH_STATUS_SUCCESS;
				}

				say_num(sh, a, SSM_PRONOUNCED);
				say_num(sh, b, SSM_PRONOUNCED);

				return SWITCH_STATUS_SUCCESS;
			}
			break;
		case SSM_COUNTED:
		case SSM_PRONOUNCED:
			if ((status = play_group(SSM_PRONOUNCED, places[11], places[10], places[9], "digits/billion", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand", sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			if ((status = play_group(say_args->method, places[2], places[1], places[0], NULL, sh)) != SWITCH_STATUS_SUCCESS) {
				return status;
			}
			//Doc phan thap phan
			if(f2){
				switch_say_file(sh, "digits/dot");
				say_num(sh, atoi(f2), say_args->method);
			}
			break;
		default:
			break;
		}
	} else {
		switch_say_file(sh, "digits/0");
	}

	return SWITCH_STATUS_SUCCESS;
}