For those who are interested I have made another TTS test program.
A simple conversion of a message to Speech, and then dial a number and play the message.
I used a simple JScript TTS converison before Christmas.
But now I have revisited it and converted to PHP
Much simpler in my view.
Here is the basic code for a text to speech conversion with an auto dial out afterwards.
First you will need to install the AWS PHP SDK
https://aws.amazon.com/sdk-for-php/
Here is the code
// Text to Speech test
defined(â_JEXECâ) or die(âRestricted accessâ);
// point to the PHP SDK helper
require âttsaws/aws-autoloader.phpâ;
Variables passed from upper program.
$fnnto = isset($fnnto) ? $fnnto : â12345678â;
$message = isset($message) ? $message : âHello Worldâ;
$error=false;
$awsAccessKeyId = âYour Access key goes hereâ;
$awsSecretKey = âYour Secret Key goes hereâ;
// set the credentials
$credentials = new Aws\Credentials\Credentials($awsAccessKeyId, $awsSecretKey);
// create request
$client = new Aws\Polly\PollyClient([
âversionâ => â2016-06-10â,
âcredentialsâ => $credentials,
âregionâ => âus-east-1â,
]);
// set output type and Voice
$result = $client->synthesizeSpeech([
âOutputFormatâ => âmp3â,
âTextâ => $message,
âTextTypeâ => âtextâ,
âVoiceIdâ => âRussellâ,
]);
$resultData = $result->get(âAudioStreamâ)->getContents();
$filePath=âttsout/outboundmsgs/â;
$fileName=âcall12345678.mp3â;
$local_mp3_file = $filePath . $fileName;
// write it out
file_put_contents($local_mp3_file, $resultData); // write mp3 file content to file
// That is all that is required to create the MP3 file
// now create the outbound call
// I am using a form from Joomla. Use straight php if required
jimport( âjoomla.filesystem.fileâ );
// remove previous call file if there
$myFile = âttsout/testcall.callâ;
unlink($myFile) or die(âCouldnât delete fileâ);
$strc=âChannel: SIP/Your-SIP-Trunk-Name-goes-here/â;
$strlf="\n";
$str1=$strc.$fnnto.$strlf;
$str2=âCallerid: 777888999â;
$str3=âMaxRetries: 5\nâ;
$str4=âRetryTime: 300\nâ;
$str5=âWaitTime: 45\nâ;
$str6=âContext: outboundmsg1\nâ;
$str7=âExtension: s\nâ;
$str8=âPriority: 1\nâ;
$output1 = $str1.$str2.$str3.$str4.$str5.$str6.$str7.$str8;
$file=âttsout/testcall.callâ;
$buffer=$str1;
$use_streams=false;
// create the file
$status = Jfile::write($file, $output1, $use_streams=false);
// wait to make sure it is flushed out to disk
sleep(5);
// output to outgoing calls so Asterisk will action it
copy(âttsout/testcall.callâ, âttsout/outgoing/testcall.callâ);
You will also need a context in Freepbx called outboundmsg1
See above code
In FreePBX GUI goto Config edit
Edit extensions_custom.conf
add this code
[outboundmsg1]
exten => s,1,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds
exten => s,2,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds
exten => s,3,Answer
exten => s,4,Wait(1)
exten => s,5,Background(/var/spool/asterisk/outboundmsgs/call12345678) ;"play outbound msg"
exten => t,2,Hangup
Thatâs All Folks.