zaf / asterisk-googletts

Asterisk AGI script that uses Google's translate text to speech service.
GNU General Public License v2.0
214 stars 125 forks source link

Interrupt keys in php agi script. #13

Closed jeetzz closed 10 years ago

jeetzz commented 10 years ago

Hi Zaf,

Its me again :) hope you doin okay! Ive run into a problem where I have the followin executed in php agi. Currently I am using get_data to receive the DTMF and execute the condition attached to it. My problem is that the DTMF is not accepted till the complete options are read out by googletts, hence I would like to use the interrupt keys function provided by you to invoke the reading and execute the DTMF. Is there a way to do it in php agi?

If you could plllllllllllllleeeeeeeaaaaseeeee shed some light.

{
$agi->exec("AGI","googletts.agi,\"Some text $variable1\",en,");
$agi->exec("AGI","googletts.agi,\"Some text 2 $variable2\",en");
$agi->exec("AGI","googletts.agi,\"Some text 3 $variable3 \",en");
$agi->exec("AGI","googletts.agi,\"Some text 4 $variable4 \",en");
$agi->exec("AGI","googletts.agi,\"or press zero for the operator\",en");

//grab user input data from history options
$press1 = $agi->get_data('silence/1',50000, 1);
$press1dtmf = $press1['result'];

if ($press1dtmf=="1") 
{
$agi->exec("AGI","googletts.agi,\"We are sorry! This feature is currently not available. Your call is now being transferred to our operator.\",en");
$agi->exec('transfer',"SIP/123@123.456.789.10:5080");   
$agi->hangup();
} 

if conditions continued......

zaf commented 10 years ago

At the moment googletts.agi can do 2 things: -Playback the generated sound prompt using the STREAM FILE AGI command. In this case no input is accepted, playback can't be interrupted and nothing is returned by the script. -Playback the generated sound prompt using STREAM FILE with the interrupt key value set. In this case the script accepts digits from the caller as input, interrupts the playback if the input matches the interrupt digit and proceeds the dialplan execution to the extension matching the given digit. (for details check the function playback() in googletts.agi)

I guess that none of the above can match the functionality you are trying to replicate in your code. Googletts.agi will not interrupt the playback and return the received digit in your code, or let your code receive the users input. That's why I have already suggested that you should try to re-implement parts of googletts in your own code so that you can adjust it to your needs. Calling an AGI script from within an AGI script is not very handy.

jeetzz commented 10 years ago

Hi Zaf, Thanks for your reply. Okay I understand your point... is there a possibility you could share some sort of guide or a tutorial that I could look at before implementing googletts in my php agi code.

Thanks for your help.

zaf commented 10 years ago

As I said the code is there for reading and studying ;) In general you send a get request formed like that: http://translate.google.com/translate_tts?tl=en&q=Hello where 'tl' is the language and 'q' the string you want to synthesize (remember to escape it properly). This will give you back the voice data in mp3 format. The tricky part is that it accepts strings only up to 100 characters long, so if your input string is bigger you have to cut it down accordingly. In googlettts we use this regex: /.{1,99}[.,?!:;]|.{1,99}\s/g to partition the original string to a series of strings no bigger than 100 chars, cutting it down to the closest punctuation mark or space before the 100 char limit so we don't cut words in half. Then we submit each string in a separate request. Another thing to have in mind is that it drops requests that are not coming from web browsers, so make sure your script imitates some desktop browser by setting the user agent header accordingly.

jeetzz commented 10 years ago

Thanks a lot zaf :100: ....I will have a crack at it. Hopefully it,ll be one without flaws :)