CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [FishMonger] Google TTS script advice: Edit Log


Jan 3, 2013, 8:41 AM

Views: 4990
Re: [FishMonger] Google TTS script advice

I am trying to setup a local DID so people calling us here don't get charged for an international call.

When the call comes in, the CallerID number is checked against entries in AstDB to make sure only authorised numbers can use this system.

Once this is established, it checks for local time and plays a prompt stating the local time asking the caller if she still wants to proceed.

Should the caller choose to go through, it then rings our phone while the caller is waiting to be connected.
To do this, I am using Dial(SIP/trunk/ournumber,,A(/path/to/generated/file.sln)) so that when we pick up the phone there is an annoucement of who is calling asking us if we want to take the call or not.

I'd rather not pre-record all the names because there are quite a few, and also because I'd like to keep this as dynamic as possible making it easy to add and remove authorised callers with just a line of code.

I am using the googletts.agi script for all my other prompts because it works perfectly.
But Dial() 'A' option will only take a sound file, it will not call a script to generate and play this sound file. The AGI script cannot be called in this case and this is where I'm stuck.

I have done a bash script that does a wget to google, saves the mp3 and converts it to sln with mpg123 then sox and saves it. It works fine when I run it myself in the shell but when I call it with Asterisk it doesn't work anymore.

If I run the bash script myself and comment the lines calling the bash script in the dialplan, the announcement plays fine.

Here is the bash script:

#!/usr/bin/env bash 
# Renders callername using Google TTS API
# call it with callername lang
wget -O /tmp/galacb_name_announce.mp3 --user-agent="Mozilla/5.0 (X11\; Linux\; rv:8.0) Gecko/20100101"$2\&q=$1+calling

mpg123 -w /tmp/galacb_name_announce.wav /tmp/galacb_name_announce.mp3

sox /tmp/galacb_name_announce.wav -t raw -r 8000 -c 1 /tmp/galacb_name_announce.sln

rm /tmp/galacb_name_announce.mp3
rm /tmp/galacb_name_announce.wav

chown root.root /tmp/galacb_name_announce.sln
chmod 644 /tmp/galacb_name_announce.sln

exit 0

Here is how I am calling it in the extensions.conf

exten => start,1,agi(googletts.agi,"Calling Gala now, please wait...",en)
same => n,Set(callername=${DB(auth_cid/${CALLERID(num)})})
same => n,Set(caller_name_announce="/home/user/ ${callername} en")
same => n,System(${caller_name_announce}))
same => n,NoOp(${caller_name_announce})
same => n,Dial(SIP/voipms/15551231234,,A(/tmp/galacb_name_announce))

exten => h,1,System(rm /tmp/galacb_name_announce.*)

And here is the console being upset at it:

    -- Executing [1@checklocaltime:1] Goto("SIP/user1-00000082", "call-gala,start,1") in new stack 
-- Goto (call-gala,start,1)
-- Executing [start@call-gala:1] AGI("SIP/user1-00000082", "googletts.agi,"Calling Gala now, please wait...",en") in new stack
-- Launched AGI Script /usr/share/asterisk/agi-bin/googletts.agi
-- Playing '/tmp/5f93250388561e955898ba34bd4e7350' (escape_digits=) (sample_offset 0)
-- <SIP/user1-00000082>AGI Script googletts.agi completed, returning 0
-- Executing [start@call-gala:2] Set("SIP/user1-00000082", "callername=someuser") in new stack
-- Executing [start@call-gala:3] Set("SIP/user1-00000082", "caller_name_announce="/home/user/ someuser en"") in new stack
-- Executing [start@call-gala:4] System("SIP/user1-00000082", ""/home/user/ someuser en")") in new stack
-- Executing [start@call-gala:5] NoOp("SIP/user1-00000082", ""/home/user/ someuser en"") in new stack
-- Executing [start@call-gala:6] Dial("SIP/user1-00000082", "SIP/voipms/15551231234,,A(/tmp/galacb_name_announce)") in new stack
== Using SIP RTP CoS mark 5
-- Called SIP/voipms/15551231234
-- SIP/voipms-00000083 is making progress passing it to SIP/user1-00000082
-- SIP/voipms-00000083 answered SIP/user1-00000082
[Jan 2 18:34:50] WARNING[28795][C-00000069]: file.c:698 ast_openstream_full: File /tmp/galacb_name_announce does not exist in any format
[Jan 2 18:34:50] WARNING[28795][C-00000069]: file.c:1014 ast_streamfile: Unable to open /tmp/galacb_name_announce (format (ulaw)): No such file or directory
[Jan 2 18:34:50] ERROR[28795][C-00000069]: app_dial.c:2758 dial_exec_full: error streaming file '/tmp/galacb_name_announce' to callee
-- Remotely bridging SIP/user1-00000082 and SIP/voipms-00000083
-- Executing [h@call-gala:1] System("SIP/user1-00000082", "rm /tmp/galacb_name_announce.sln") in new stack
== Spawn extension (call-gala, start, 6) exited non-zero on 'SIP/user1-00000082'

I was thinking it would work better in Perl for some reason since the AGI scripts are in Perl.

I'm quite stuck here, don't really know where to go from there to be honest.

(This post was edited by HumbuckingCoil on Jan 3, 2013, 8:48 AM)

Edit Log:
Post edited by HumbuckingCoil (Novice) on Jan 3, 2013, 8:43 AM
Post edited by HumbuckingCoil (Novice) on Jan 3, 2013, 8:48 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives