Polly is an Amazon AI service that uses advanced deep learning technologies to synthesize speech that sounds like a human voice. Polly includes 47 lifelike voices spread across 24 languages, so you can select the ideal voice and build speech-enabled applications that work in many different countries.
Important remark
The following procedures were performed in a test environment, the propolys-tts.agi file will be modified and then FreePBX will alert you as per the text below;
Module: “Text To Speech”, File: "/var/www/html/admin/modules/tts/agi-bin/propolys-tts.agi altered"
Create Custom Engine:
Sample project to demonstrate usage of the AWS SDK for Node.js:
cd /opt/
git clone https://github.com/awslabs/aws-nodejs-sample
cd aws-nodejs-sample
npm install
npm install optimist
npm install child_process
vim script.js
// Load the SDK
var argv = require(‘optimist’).argv;
const AWS = require(‘aws-sdk’)
const Fs = require(‘fs’)
var child_process = require(‘child_process’);
// Create an Polly client
const Polly = new AWS.Polly({
accessKeyId: “accessKeyId here”,
secretAccessKey: “secretAccesKey here”,
signatureVersion: ‘v4’,
region: ‘us-east-1’
})
let params = {
‘Text’: argv.text,
// ‘Text’: ‘Tatiana’,
‘OutputFormat’: ‘mp3’,
‘SampleRate’: ‘8000’,
‘VoiceId’: ‘Vitoria’
}
Polly.synthesizeSpeech(params, (err, data) => {
if (err) {
console.log(err.code)
} else if (data) {
if (data.AudioStream instanceof Buffer) {
Fs.writeFile(argv.mp3, data.AudioStream, function(err) {
if (err) {
return console.log(err)
}
console.log(“The file was saved!”)
var output = child_process.execSync('lame --decode ’ + argv.mp3 + ’ ’ + ‘-b 8000’ + ’ ’ + argv.wav + ‘.wav’);
})
}
}
})
vim /var/lib/asterisk/agi-bin/propolys-tts.agi
case 'node':
exec($enginebin." /opt/aws-nodejs-sample/script.js --mp3=/var/lib/asterisk/sounds/tts/$engine-tts-$hash.mp3 --text='$text' --wav=/var/lib/asterisk/sounds/tts/$engine-tts-$hash");
break;
Installing Lame to convert mp3 to wav on Freepbx Centos 7:
The Amazon Polly service returns the audios in the following formats, mp3, pcm and ogg, I used the mp3 format but it was necessary to convert from mp3 to wav 8000hz:
yum -y install lame
Now you can use the tts module with Amazon Polly:
Finally
Go to Applications=> Text to Speech and create your TTS with engine Polly.