login | register
Wed 09 of Jul, 2008 [05:51 UTC]

voip-info.org

Discuss [8] History

Asterisk cmd Festival

Created by: oej,Last modification on Thu 06 of Dec, 2007 [14:53 UTC] by eborger

Synopsis

Say text to the caller

Description:

 Festival(text,intkeys)

Uses the Festival open-source speech synthesizer (which you need to have installed) to generate the specified text as a sound stream. The intkeys parameter is optional. If present, it specifies the buttons that, if dialed by the caller, will cause the playing of the sound stream to stop, and for Festival returns the button pressed. If you specify the intkeys parameter as "any", then Festival will return at the first button dialed, regardless of what it is. Please note that the intkeys parameter has to be enclosed by single quotes (') and there must not be a space between text, the comma and intkeys (see example).

The text parameter should be enclosed in quotation marks if there are any spaces.

Festival is not an application that will automatically answer the channel - so you need to do it yourself.

Example

  exten => 003,1,Answer
  exten => 003,2,Festival('Hello asterisk user, how are you today?')   ; <-- note the quotes ... 
  exten => 003,3,Festival('And an example the user can stop by pressing any key','any')  ; note quotes and no spaces
Remember to Answer the channel before using the Festival command.

Tip

You may get better results using the System command to access Festival's text2wave program to generate a .WAV file, and then use the Background or Playback commands, rather than using Asterisk's Festival command.

% text2wave -o myfile.ulaw -otype ulaw

Will take text from stdin and make a sound file of the text in ulaw format. You can simply use Playback(myfile) to play it through asterisk.
If you have problems with Festival seeming to drop some of the text, this may be for you. Also, if you have a lot of intensive processing (this in itself is intensive processing) you may want to spin this off into the background, and then play music or instructions for your user in the meantime. For example:

exten => s, 1, System(do_stuff &)
exten => s, 2, Playback(introduction-instructions)
exten => s, 3, Playback(my_new_sound)

 *****   do_stuff *****
 #!/usr/bin/php
 <?php
 // Take care of all your processing.
 $data = "A lot of text or something here.";
 system("echo $data | text2wave -o my_new_sound.ulaw -otype ulaw -");
 ?>

Something like that will allow you to do a bunch of heavy processing without forcing the user to wait on you.


See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments

Comments Filter
222

333Problem with Festival and text2wave

by chesstrian, Wednesday 09 of April, 2008 [22:42:46 UTC]
I have configured Asterisk with phpagi, and i have installed festival for use text2wave, it's working, but i need voices in spanish and i can't change language; Thanks for any help.

PD: Festival is not running as a daemon.
222

333Another php snippet to handel festival

by dthompso99, Thursday 24 of May, 2007 [12:37:38 UTC]
here is a script similar to the perl script listed above, executing as a background command.<br>
in dialplan:

exten => s,n,AGI(say.php|Welcome\, bla bla bla)


in say.php:


  1. !/usr/bin/php -q
<?php
$tts_dir = "/var/lib/asterisk/sounds/tts";
set_error_handler('file_errors');
//$input = fread(STDIN, 1024);
if ($_SERVERargv>'argv'1){
$tmp_name = md5($_SERVERargv>'argv'1);
if (!(file_exists($tts_dir."/".$tmp_name.".wav"))){
$cmd_txt2wave = "echo ".$_SERVERargv>'argv'1."| text2wave -o ".$tts_dir."/".$tmp_name.".wav";
exec($cmd_txt2wave);
$cmd_sox = "sox ".$tts_dir."/".$tmp_name.".wav -r 8000 -c 1 ".$tts_dir."/".$tmp_name.".gsm resample -ql";
exec($cmd_sox);
//we'll leave the gsm file as a cache
unlink($tts_dir."/".$tmp_name.".wav");
}
fputs(STDOUT,"EXEC BACKGROUND \"tts/".$tmp_name."\"");
}


function file_errors($errno, $errmsg, $filename, $linenum, $vars){
$logfile = fopen("//var//log//say.log","a+");
fwrite($logfile, "(".date("Y-M-d").") $errno - $errmsg\r\n");
fclose($logfile);
}
?>

222

333Change voice for Festival

by scarykidsscaringkids, Monday 25 of September, 2006 [05:21:21 UTC]
I've downloaded Asterisk 1.4.0 and was trying to use Festival. I got it up and running with voice. But I don't really like the default voice i hear, is there anyway i can change it? I don't see much help.
222

333Mbrola works also

by adlerweb, Monday 19 of June, 2006 [21:16:58 UTC]
I used mbrola for some time and modified the php-script. Here is my first result (shellscript) - just change the locations:


(hash)!/bin/sh
cat /dev/stdin | \
sed 's/@/ <E4>t /g' | \
pipefilt | \
preproc ???/preproc/Rules.lst ???/preproc/Hadifix.abk | \
txt2pho -m | \
mbrola -f 0.8 -t0.8 -l 15000 ????/de2/de2 - -.au > /tmp/asterisk.au
sox /tmp/asterisk.au -r 8000 -c 1 /var/lib/asterisk/sounds/tts.gsm<br />
rm /tmp/asterisk.au

Exten:

exten => 31,1,Answer
exten => 31,2,system(echo \'Welcome to the wonderful world of Asterisk! Your phone number is ${CALLERIDNUM}.\' | ???/asterisk.sh)
exten => 31,3,wait(1)
exten => 31,4,Playback(tts)
exten => 31,5,Hangup
222

333text2wave php script

by sbotig, Sunday 09 of April, 2006 [20:01:52 UTC]
because that festival() stuff didn't work, here's how i did it:
i made a php script... you could also make it in perl or python or whatever you like...

/scripts/fest.php:
  1. !/usr/bin/php5 -q

<?php
$dir="/var/lib/asterisk/sounds/";
$textfilename="newfile.txt";

$textfile=$dir.$textfilename;
if (file_exists($textfile)){
       unlink ($textfile);
}
touch($textfile);
$tfile=fopen($textfile, "w");
//echo $argv1;
fwrite($tfile, $argv1);
fclose($tfile);
if(file_exists($dir."newsound.gsm")){
       unlink ($dir."newsound.gsm");
}
system("text2wave -f 8000 -o ".$dir."newsound.wav ".$textfile);
system("sox ".$dir."newsound.wav -r 8000 -c 1 ".$dir."newsound.gsm");
unlink($dir."newsound.wav");
?>


...and create an extension for testing...

exten => 31,1,Answer
exten => 31,2,system(/scripts/fest.php \'Welcome to the wonderful world of Asterisk! Your phone number is ${CALLERIDNUM}.\')
exten => 31,3,wait(1)
exten => 31,4,Playback(newsound)
exten => 31,5,Hangup

the script should have execute rights and the asterisk sounds directory should be writable by the script... have fun!
222

333weather forecasts

by joel, Sunday 13 of March, 2005 [02:03:28 UTC]
here's an example for getting automated daily forecasts read to you by festival.

create a cron job e.g. /etc/cron.daily/weather
add to it something like this:
wget -O - ftp://tgftp.nws.noaa.gov/data/forecasts/city/pa/pittsburgh.txt | \
tail --lines=+3 | text2wave -f 8000 -o /usr/share/asterisk/sounds/my-weathe\
r.wav

then in extensions.conf
; 091 for the weather
exten => 091,1,Answer
exten => 091,2,Playback(my-weather)
exten => 091,3,Hangup


222

333Example of text2wave

by alakon, Friday 25 of February, 2005 [21:16:08 UTC]
The author suggests the use of the "text2wave" command through system to generate the file... can you give us an example? The syntax is really tricky.

Thanks!
222

333How can i change the language in asterisk?

by , Monday 08 of November, 2004 [11:46:17 UTC]
How can i change the language in asterisk?(:sad:)(:sad:)(:sad:)(:cry:)(:cry:)