2. Click2Call service.

click2dial-button from George on Vimeo.


This addon is for WEB sites owners. It helps to contact with site visitors directly, without making international or local calls. Idea to use HTML5 and WEBRtc was initially described by Doubango telecom : http://click2dial.org

Simple solution: using a2billing interface, customer configure (sets destination) and design (colors, image, text), finally — generates a short html code of the button, which can be placed on his web site pages. While visitor clicking, popup box asks to provide contact phone number. Within 10-20 seconds, visitor gets incoming call from web site company. It is done by cross-domain request (from customer WEB page to asterisk server), first — generates a call to specified location ( company number ), once connected — asterisk calls visitor provided number and connect two calls together.

 

click2call

Button to make visitors calling back feature

 

 

 

Both modules are easy to install, but require Asterisk cli administration skills to fix errors and install missed programs ( sox, mpg123, perl modules, path correction)

On web page, where you play text2speech function, I made automatically convertion to mp3 , the most supported format for browsers. It is done by file play_mp3.php.
It accept text, and return media data — the text convereted to speech by google. Also, it plays regual asterisk prompts media files.

here is the code,

<?php
 $media_folder="/var/lib/asterisk/sounds";
 $f= $media_folder . '/' . $_GET['f'];
 $f = file_exists( $f . '.ogg' )? $f . '.ogg' : $f;
 $f = file_exists( $f . '.wav' )? $f . '.wav' : $f;
 $f = file_exists( $f . '.gsm' )? $f . '.gsm' : $f;
 // We have text2Speech function here //
 if ( $_GET['t'] ) { 
 // Download media file now:
 $text2speech = trim(urldecode($_GET['t']));
 $cachedir = "/tmp";
 $lang = 'en-US';
 $speed = 1;
 $filename = md5("{$text2speech}..{$lang}.{$speed}").'.sln';
 $f = "$cachedir/$filename";
 if ( filesize( $f ) < 1 ) {
 unlink($f);
 }
 if ( !file_exists( $f ) ){
 $text2speech = urlencode($text2speech); 
 $URL = "https://translate.google.com/translate_tts?ie=UTF-8&q={$text2speech}&tl=en&total=1&idx=0&client=t";
 $ch = curl_init( $URL );
 curl_setopt( $ch, CURLOPT_REFERER,"https://translate.google.co.uk/");
 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 1);
 curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36");
 $header[] = "Accept-Language: en-us,en;q=0.5";
 curl_setopt( $ch, CURLOPT_HTTPHEADER, $header);
 $data = curl_exec ($ch); 
 $tmp = '/tmp/convert_tts.sln';
 if (file_exists($tmp) ) { 
 unlink($tmp);
 }
 $h = fopen( $tmp, "w+");
 fputs($h, $data);
 fclose($h);
 system("/usr/bin/mpg123 -q -w /tmp/convert_tts.wav $tmp");
 system("/usr/local/bin/sox /tmp/convert_tts.wav -t raw -q -r 8000 $f 2>/dev/null");
 }
 } 
 if ( ! file_exists("{$f}") ) {
 header("HTTP/1.0 404 Not Found");
 return;
 }
 $tmp_mp3 = "/tmp/file.mp3";
 $tmp_wav = "/tmp/file.wav";
 if ( file_exists($tmp_mp3)) unlink($tmp_mp3);
 if ( file_exists($tmp_wav)) unlink($tmp_wav);
 system("/usr/local/bin/sox $f -c 1 $tmp_wav 2>/dev/null");
 system("ffmpeg -y -i $tmp_wav -acodec libmp3lame $tmp_mp3 2>/dev/null");
 if ( file_exists($tmp_mp3) ){
 header('Content-Disposition: filename="' . $tmp_mp3 . '"');
 header('Content-length: '.filesize($tmp_mp3));
 header('Cache-Control: no-cache');
 header("Content-Transfer-Encoding: chunked"); 
 header("Content-Type: audio/mpeg");
 readfile($tmp_mp3);
 }else{
 header("HTTP/1.0 404 Not Found");
 exit;
 }
?>
PDF Download    Send article as PDF