01. Register in twilio
Link : https://www.twilio.com/try-twilio
Register your account from above link, and fill all the details.
02. Get your authentication details
Login with your username and password,
and Go to https://www.twilio.com/console page.
Get your ACCOUNT SID and AUTH TOKEN, this details will required in your REST API.
03. Text to Speech API
Now using IndianTTS Text to Speech API and convert your text to audio format, refer bellow code for TEXT to Speech API
<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials: true "); header("Access-Control-Allow-Methods: OPTIONS, GET, POST"); header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control"); $host = '<TTS API HOST>'; $port = '<PORT>'; $text = <TEXT>; $url = "http://".$host.":".$port."/tts?text=".$text; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_PORT => "<PORT>", CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?>
04. Integrate Twilio API code
Link : https://www.twilio.com/console/dev-tools/api-explorer/voice/call-create
Now using your ACCOUNT SID, AUTH TOKEN and audio URL (which is return from TTS) integrate twilio code, code screen shot is bellow
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size,
X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
$mobile = $_POST["mobile"];
$audio = $_POST["audio"];
require_once __DIR__ . '/twilio-php-master/Twilio/autoload.php'; // Loads the library
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "<Account SID>";
$token = "<Account Token>";
$client = new Client($sid, $token);
$call = $client->calls->create(
"+91".$mobile, "<Your Mobile Number>",
array("url" => "<Audio URL>"
);
echo $call->sid;
?>