@GTCNetworking wrote:
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 codeIn 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,HangupThat’s All Folks.
Posts: 1
Participants: 1