[Asterisk-Users] TTS via text2wave

Donny Kavanagh kavando at trn.ca
Sun Oct 10 17:03:48 MST 2004


Could these files be cached as well?

Donny 

-----Original Message-----
From: Paul Dugas [mailto:Paul at DugasEnterprises.com] 
Sent: October 10, 2004 12:56 PM
To: Asterisk Mailing List
Subject: [Asterisk-Users] TTS via text2wave

Tinkering with getting a text-to-speech component worked into my dial
plan without having to run the Festival server.  Entries in
extensions.conf and the tts.agi script are below.  I know I must be
close as it worked once. 
Was shocked as it was after about 50 different tries.  Tried it again
and it didn't work.  Been tinkering since so the script is not exactly
the same but it's close.

Thinking the file may have been deleted before it was played, I've tried
clearing the UNLINK option to tempfile() but still no luck.

When the file was being created in '/tmp/ but * was lookig in
.../sounds, I would get an eror indicating it couldn't find the file so
I know the "STREAM FILE" command was being sent.  When I fixed the
paths, the error went away.

Log message from the console were:

    -- Executing Wait("SIP/106-5a8d", "1") in new stack
    -- Executing AGI("SIP/106-5a8d", "tts.agi|Shall we play a game?") in
new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/tts.agi
  tts.agi|Shall we play a game?: FORKING text2wave
  tts.agi|Shall we play a game?: CREATED
/var/lib/asterisk/sounds/HykFjnCdwu-tts.wav
  tts.agi|Shall we play a game?: DONE
    -- AGI Script tts.agi completed, returning 0
    -- Executing Hangup("SIP/106-5a8d", "") in new stack

"extensions.conf" entries like so:

  exten => 7003,1,Wait(1)
  exten => 7003,2,AGI(tts.agi|Shall we play a game?)
  exten => 7003,3,Hangup

"tts.agi" script like so:

   #!/usr/bin/perl -w
   #
   # tts.agi - AGI script for test-to-speech using Festival's text2wave
   #

   # modules
   use strict;
   use Asterisk::AGI;
   use File::Basename;
   use File::Temp;

   # defined
   use constant SOUNDS    => '/var/lib/asterisk/sounds';
   use constant TEXT2WAVE => '/root/work/festival/bin/text2wave';
   use constant TEXT      => join( ' ', @ARGV );

   # init AGI
   my $AGI = new Asterisk::AGI;
   my %input = $AGI->ReadParse();

   # temp file
   my (undef, $tmpfile) = File::Temp::tempfile( DIR    => SOUNDS,
                                                SUFFIX => '-tts.wav',
                                                UNLINK => 1 );

   $AGI->verbose( "FORKING text2wave\n", 4 );

   # fork
   my $pid = open my $pipe, "|-";
   die "fork() failed: $!" unless defined $pid;
   if ( !$pid )
     {
       # child
       open STDOUT, ">$tmpfile" or die "can't redir to $tmpfile: $!";
       exec TEXT2WAVE, '-F', '8000', '-';
       die "exec() failed: $!";
     }
   else
     {
       # parent
       print $pipe TEXT;
       close $pipe;
       waitpid $pid, 0;
       $AGI->verbose( "CREATED $tmpfile\n", 4 );
       $AGI->stream_file( basename( $tmpfile, '.wav' ) );
     }

   # outahere
   $AGI->verbose( "DONE\n", 4 );
   0;

Any suggestions appreciated,

Paul
--
Paul A. Dugas                               Dugas Enterprises, LLC
email: paul at dugasenterprises.com            1711 Indian Ridge Drive
phone: 404.932.1355  fax: 770.516-4841      Woodstock, GA 30189 USA
   [ onsite at the Georgia DOT's West Annex, 404.463.2860 x158 ]
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users



More information about the asterisk-users mailing list