[Freeswitch-users] Patch to fix italian pronunce in mod_say_it
Brian West
brian at freeswitch.org
Tue Nov 10 06:10:16 PST 2009
Can you post your patch to jira.freeswitch.org please.
/b
On Nov 10, 2009, at 7:00 AM, Albano Daniele Salvatore - Lavoro wrote:
> Hi,
>
> yesterday i started to fix pronuce in mod_say_it for numbers, dates
> and times. I needed to add some sound files because these was
> necessary for a correct italian pronunce.
>
> I've patched these three functions:
> - play_group
> - it_say_time
> - it_say_general_count
>
> I've diff it against revision 15396 (i've updated freeswitch tree
> yesterday morning)
>
> Can you take a look to the patch?
>
>
>
> # Modification to play_group function
>
> In italian we pronunce 123 as "cento venti tre" and not "uno cento
> venti tre" so, if a is 1 just doesn't play the digit
>
>
>
> # Modification to it_say_time
>
> Our long date format is something like
>
> WDAY_NAME, WDAY_NUMBER MONTH_NAME YEAR
>
> so i converted the date pronunce to this.
>
> I've dropped am/pm logic, because we have 24h standard, and minutes
> related logic because, we don't have it.
>
>
>
> # Modification to it_say_general_count
>
> I rewrote number to string conversion to make it more readable
> (using just two math operations, a module and a division) and to
> drop the 999 milions limit (1*)(however more code should be changed
> to fully drop this limit).
>
> Changes are mainly related to millions and thousands pronunce: in
> italian, if you need to say 1 milion you doesn't say "uno milione"
> but "un milione" but to say 3 millions you say "tre milioni", while
> for thousand you doesn't pronunce "un" at all.
>
>
> 1*: i've noticed a little bug in xx_say_money in mod_say_xx ... it
> get up to 12 digits but in xx_say_general_count manage up to 9
> digits, so the first three digits wouldn't get never pronunced
>
> Thank you
>
> Index: src/mod/say/mod_say_it/mod_say_it.c
> ===================================================================
> --- src/mod/say/mod_say_it/mod_say_it.c (revisione 15396)
> +++ src/mod/say/mod_say_it/mod_say_it.c (copia locale)
> @@ -95,7 +95,9 @@
> {
>
> if (a) {
> - say_file("digits/%d.wav", a);
> + if (a != 1) {
> + say_file("digits/%d.wav", a);
> + }
> say_file("digits/hundred.wav");
> }
>
> @@ -170,7 +172,7 @@
> char *tosay, switch_say_type_t type, switch_say_method_t
> method, switch_input_args_t *args)
> {
> int in;
> - int x = 0;
> + int places_count = 0;
> int places[9] = { 0 };
> char sbuf[13] = "";
> switch_status_t status;
> @@ -179,26 +181,64 @@
> 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 isin't zero
> 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;
> - }
> - }
> -
> +
> + // 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 (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;
> - }
> +
> + // 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/thousands.wav", session, args)) !
> = SWITCH_STATUS_SUCCESS) {
> + return status;
> + }
> + }
> + }
> +
> + // Play last group
> if ((status = play_group(method, places[2], places[1], places[0],
> NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
> return status;
> }
> @@ -370,36 +410,19 @@
>
> if (say_date) {
> say_file("time/day-%d.wav", tm.tm_wday);
> + say_num(tm.tm_mday, SSM_PRONOUNCED);
> 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;
> + say_file("time/hours.wav");
> + say_num(tm.tm_hour, SSM_PRONOUNCED);
>
> - 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);
> -
> - if (tm.tm_min > 9) {
> + if (tm.tm_min) {
> + say_file("time/and.wav");
> say_num(tm.tm_min, SSM_PRONOUNCED);
> - } else if (tm.tm_min) {
> - say_file("time/oh.wav");
> - say_num(tm.tm_min, SSM_PRONOUNCED);
> - } else {
> - say_file("time/oclock.wav");
> }
> -
> - say_file("time/%s.wav", pm ? "p-m" : "a-m");
> }
>
> return SWITCH_STATUS_SUCCESS;
> <info.vcf>_______________________________________________
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-
> users
> http://www.freeswitch.org
More information about the FreeSWITCH-users
mailing list