Summary:ASTERISK-01707: Application that says phrases acording to given pattern
Reporter:maciejka (maciejka)Labels:
Date Opened:2004-05-27 11:53:44Date Closed:2011-06-07 14:05:10
Versions:Frequency of
Environment:Attachments:( 0) app_say.c

App_say helps in situations when one has to include some numbers into ivr announcement. For example: "You have two voicemails" Depending on particular language grammar announcement takes different form depending on number x being included, e.g.: in english:

x=1: "You have one voicemail"
x>1: "You have x voicemails"

in polish it is a little more complicated, roughly there  are three suffixes  for numbers  ending with  1, 2-4,  5-0, with  exceptions for 11-19:

x=1: "Masz jedn list"
x=2: "Masz dwa listy"
x=4: "Masz piec listow"
x=12: "Masz piec listow"
x=22: "Masz dwadziescia dwa listy"

In sutch a situation App_say allows to write simply:

exten => 5,3,Say(you have {number/$1} {voicemail/$1}|123)

and asterisk  plays files:  'you', 'have', than  calls say_number(123)
than plays file 'voicemails'.

Detailed description

App_say as arguments takes a string pattern, and a list of numbers. Processing goes on in tree stages: replacement, transformation rule application, play.


Pattern  contains  replacement  specifications  that get  replaced  by numbers from  list. Replacement specifications takes  form of /$digit, where digit is an index  of number that this replacement specification should be replaced  with.

After replacement stage  pattern:
you have {number/$1}   {voicemail/$1}  
gets transformed into:  
you have {number/123} {voicemail/123}.

Transformation rule application:

App_say is configured with set of transformation rules. For example:

During second stade for every string in curly baces app_say trys to find a matching rule for current language.  Rule matches string if regular expression on left hand side of => sign matches it.  If rule is found, string in curly braces is replaced with rule right hand side.  There is one special right hand side: number(?)  that before being used gets its '?'  replaced with what is on right side of / in string that has got matched.

So for pattern from first stage:
you have {number/123} {voicemail/123}
we get:
you have number(123) voicemails


In  this stage  pattern  is treated  as  a  list of  filenames separated with  spaces. Instead of playing filename  of form number(x) say_number(x) is executed.



A the moment app_say is in experimental stage. I publish it to find if it usefull in other than polish languages and to discuss what features it lacks.


There should be at least two more special rule right hand sides for embeding currencies and date.
Comments:By: Brian West (bkw918) 2004-05-27 12:22:30

This has already been addressed just not implemented.

By: maciejka (maciejka) 2004-05-27 12:52:43

What do You mean by that it has already addressed but not implemented?

By: Brian West (bkw918) 2004-05-27 13:59:27

we know of the problem and have a way to solve it but continued hacking of say.c has got to stop.  We are looking doing a lang_xx.so packs where the .so would provide the proper mapping to concat files into a phrase using the specific language rules in the .so lang pack.  Now if we can just get someone to work on that.



just some examples but we need something like this.  Say in app_voicemail we want to say "You have 10 new messages".  We pass it to the lang layer that then plays the files in the proper order.. now this is the idea.  But as you can see voicemail as do other apps have alot of stuff hardcodec in them.  All of that will have to be ripped out and redone also.


By: maciejka (maciejka) 2004-05-27 15:02:40

App_say is not meant to i18nze ivr apps, having different rules for different languages is just a matter of completness. Its main aim is to allow to quickly prototype single language application. Without it one would have to write one function for every announcement that contains some dynamic data. Most of this functions would be so simple that using C for it, is hardly justifiable. Speed is not a concern when prototyping, what counts is developement cycle length. While coding in C one would need to write, compile, install, restart, test, instead of write, test. So I think that there is a room for application like this in asterisk.

Having said this, I think that it is possible to i18nze voicemail and alike apps with something like app_say. Problem is similar to problem of i18ning GUIs. GUI like solution is to store message patterns in property files and let apps to choose property file according to the language. E.g.:
you_have=>you have {number/$1} {voicemail/$1}
you_have=>masz {number/$1} {list/$1}
and feed proper pattern from proper property file to app_say to play announcements. This way it would be _very_ easy to add new translations and to customise. Only limited set of funtions (numbers, dates, currency, etc) would have to be i18ned hard way (in C ;-))

What do You think?

By: Brian West (bkw918) 2004-05-29 23:37:25

Don't over complicate it.  Thats all i'm saying its simpler than anyone lets on.

By: twisted (twisted) 2004-07-01 16:46:08

It's been over a month. Closing due to loss of interest.