Toggle Navigation
elektr0n
Show page
Tools
Page Tools
Show page
Old revisions
Backlinks
Site Tools
Recent changes
Sitemap
Media Manager
User Tools
Login
Back to top
skip to content
Skip to Navigation
====== Asterisk Translator ====== * http://zaf.github.io/asterisk-googletts/ * http://zaf.github.io/asterisk-speech-recog/ * http://zaf.github.io/asterisk-googletranslate/ Required packges (CentOS) <code bash> yum install perl-Crypt-SSLeay perl-libwww-perl.noarch sox perl-JSON perl-JSON-XS flac perl-IO-Socket-SSL esound-devel libtool-ltdl wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/mpg123-1.9.1-1.el5.rf.i386.rpm rpm -i --force mpg123-1.9.1-1.el5.rf.i386.rpm </code> For Cisco 7970 Authentication, must be set in xml. <code php /var/www/html/xmlservices/auth/authenticate.php> <?php echo "AUTHORIZED"; </code> <code bash /etc/asterisk/extensions_custom.conf> [g-speech] ;Speech recognition demo also using googletts.agi for text to speech synthesis: exten => i,1,Answer() exten => i,n(start),agi(googletts.agi,"Say something in English, when done press the pound key.",en) exten => i,n(record),agi(speech-recog.agi,en) ;;exten => i,n,Verbose(1,Script returned: ${confidence} , ${utterance}) ;;exten => i,n(playback),agi(googletts.agi,"The text you just said was...",en) exten => i,n,agi(googletranslate.agi,"${utterance}",pt-BR) ;;exten => i,n,Verbose(1,Translated text: ${gtranslation}) exten => i,n,agi(googletts.agi,"${gtranslation}",pt-BR) exten => i,n,agi(transcript.agi,"${gtranslation}",pt-BR) exten => i,n,agi(pushtocisco.agi, 10.1.1.2, "http://10.1.1.1/xmlservices/translator/?lang=pt-BR") exten => i,n,goto(i,start) </code> XML service for cisco 7970. Reads transcript file and makes an xml. <code php /var/www/html/xmlservices/translator/index.php> <?php $lang = $_REQUEST['lang']; header("Content-type: text/xml"); header("Connection: close"); header("Expires: 1"); //header("Refresh: 2"); $file_data = file_get_contents($lang.'.txt'); echo '<?xml version="1.0" encoding="utf-8" ?>'; ?> <CiscoIPPhoneText> <Title>Live Translation (<?php echo $lang;?>)</Title> <Text><?php echo $file_data; ?></Text> <Prompt></Prompt> </CiscoIPPhoneText> </code> Create the transcript <code php /var/lib/asterisk/agi-bin/transcript.agi> #!/usr/bin/php <?php $myFile = "/var/www/html/xmlservices/translator/" . $argv[2] . ".txt"; $file_data = date('H:i:s') . " - " . $argv[1] . "\n"; $file_data .= file_get_contents($myFile); file_put_contents($myFile, $file_data); </code> Push translate URL to cisco 7970 <code php /var/lib/asterisk/agi-bin/pushtocisco.agi> #!/usr/bin/php -q <?php function push2phone($ip, $uri, $uid, $pwd) { $ip = trim($ip); $uri = trim($uri); $auth = base64_encode($uid.":".$pwd); $xml = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"".$uri."\"/></CiscoIPPhoneExecute>"; $xml = "XML=".urlencode($xml); $post = "POST /CGI/Execute HTTP/1.0\r\n"; $post .= "Host: $ip\r\n"; $post .= "Authorization: Basic $auth\r\n"; $post .= "Connection: close\r\n"; $post .= "Content-Type: application/x-www-form-urlencoded\r\n"; $post .= "Content-Length: ".strlen($xml)."\r\n\r\n"; $response = ''; $fp = fsockopen ($ip, 80, $errno, $errstr, 30); if (!$fp) { //error_log("$errstr ($errno)<br>\n"); } else { fputs($fp, $post.$xml); flush(); while (!feof($fp)) { $response .= fgets($fp, 128); flush(); } } //error_log($response); } $uid = "test"; $pwd = "test"; push2phone($argv[1], $argv[2], $uid, $pwd); </code>