Upgrade 3CX to v18 and get it hosted free!

Asterisk text2cepstral www demo

Author image

Image
Image

Using cepstral webbased voice synthesized demo to generate voice prompts for asterisk on the fly

Prerequisites

  • Time
  • Asterisk
  • Internet Connectivity
  • PHP (in this example we use version 5.0.4)

Introduction

Why?

I personaly wanted to be able to generate occasional voice prompts dynamicaly without the need for recording on my home PC and uploading via FTP and then moving to the correct directory on my dedicated server.

Getting Started

  1. mkdir /etc/asterisk/php/
  2. cd /etc/asterisk/php/
  3. nano speech.php

Paste into nano

<?php
$args = $_SERVER["argv"];
$i = 0;
while ($i<sizeof($args))
{
if ($i>0)
{
$arg[$i-2] = $args[$i];
}
$i++;
}
$text=urlencode(implode(" ",$arg));

system(‘rm /var/lib/asterisk/sounds/tikka.gsm’);
system(‘/usr/bin/wget -O /tmp/tikka.wav "http://qs913.pair.com/cepstral/demos/demo.cgi/cepstral.wav?content=’.$text.’&voice=Lawrence&rate=160&pitch=1&effect=none&submit=Synthesize+the+Text"’);
?>

The above code will take commandline parameters passed to it from asterisk when we call it from extentions.conf.

Press CTRL + X to close nano, it will ask if you wish to save press y for yes and then press enter to save our file with the name speech.php.

Another file that we will be creating is time.php, this is based on the same file above but generates a fun time announcement. (UK Residents will recognise this hopefuly ;))

  1. nano time.php

Paste into nano

<?php
$today = date("h:i:s");
$text = "At the third stroke, the time sponsored by accurist will be, ";
$text .= date("’h’") . "" . date("’i’") . " and " . date("’s’") . " seconds BEEP BEEP BEEP";
system(‘rm /var/lib/asterisk/sounds/time.gsm’);
system(‘/usr/bin/wget -O /tmp/time.wav "http://qs913.pair.com/cepstral/demos/demo.cgi/cepstral.wav?content=’.$text.’&voice=Lawrence&rate=160&pitch=1&effect=none&submit=Synthesize+the+Text"’);
?>
  1. cd ..
  2. nano extentions.conf

Paste into extentions.conf

[inbound]
exten => _X.,1,Answer
exten => _X.,2,System(php -q /etc/asterisk/php/speech.php Please Wait.) ; tells caller to "please wait"
exten => _X.,3,System(sox /tmp/tikka.wav -r 8000 -c 1 -s -w /var/lib/asterisk/sounds/tikka.gsm resample -ql) ; using sox (sox.sourceforge.net) encode our new wave file downloaded from cepstral website to a format more comfortable to asterisk for sending to our caller.
exten => _X.,4,Playback(tikka) ; playback the file tikka(.gsm) contained in /var/lib/asterisk/sounds/
exten => _X.,5,Wait,1
exten => _X.,6,System(php -q /etc/asterisk/php/time.php) ; this is our time generation script
exten => _X.,7,System(sox /tmp/time.wav -r 8000 -c 1 -s -w /var/lib/asterisk/sounds/time.gsm resample -ql)
exten => _X.,8,Wait,1
exten => _X.,9,Playback(time)
exten => _X.,10,Wait,5

Breakdown of PHP Script

<?php //begin php code
$text = "At the third stroke, the time sponsored by accurist will be, "; // set our intro message
$text .= date("’h’") . "" . date("’i’") . " and " . date("’s’") . " seconds BEEP BEEP BEEP"; // get hour, minute and seconds and complete our message sentance.
system(‘rm /var/lib/asterisk/sounds/time.gsm’); // delete the old time.gsm file
system(‘/usr/bin/wget -O /tmp/time.wav "http://qs913.pair.com/cepstral/demos/demo.cgi/cepstral.wav?content=’.$text.’&voice=Lawrence&rate=160&pitch=1&effect=none&submit=Synthesize+the+Text"’); // using wget, grab the wave file generated by the cepstral demo website and save it to /tmp/ with the filename time.wav
?> // close script tag

Save your new time.php script, reload extentions.conf in asterisk.

Ring your asterisk box.. enjoy!

For more scripts in the future checkout my website http://www.tikka-d.co.uk (currently no asterisk information however).


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.
Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.