| speech_pm documentation | Contained in the speech_pm distribution. |
Speech::Festival::Synthesiser - Simple text-to-speech using festival.
use Speech::Speech::Festival::Synthesiser; $festival = new Speech::Festival::Synthesiser 'serverhost', 1314; start $festival; stop $festival; @voices = voice_list $festival; voice $festival "myvoice"; voice_description $festival; synth_description $festival; speak $festival $text;
Speech::Festival::Synthesiser provides a simple way to add speech to a perl application. It is a sub-class of Speech::Festival and so you can use any of the methods in that class to manipulate festival if necessary.
This package conform to the interface defined by Speech::Synthesiser and so provides a synthesiser for use throughthat interface.
Actual sound output is provided by an auiliary class, by default Audio::FileWave which runs an external program to play sound, but you can replace it with another class if you have a better way of playing sounds (eg a perl extension providing sound output), see the documentation for Audio::FileWave for the interface an alternative should provide should implement.
If you do use Audio::FileWave you may need to set up the command it uses to play sounds, see the documentation for set_play_command in Audio::FileWave.
Create a new festival session which will connect to the given host and port. If ommitted these default to localhost and 1314.
Connect to festival and inistilise the session. Returns true if all is well, false otherwise. In the event of an error the variable $festival_error conatains a description of it.
Disconnect from festival. The connection may be reopened later with start, but any state will have been lost.
Return a list of the voices available from this server.
Select a voice.
Returns the description of the current voice.
Synthesize the standard festival introductory text.
Speak the given text.
Richard Caley, R.Caley@ed.ac.uk
Speech::Synthesiser, Speech::Festival, Audio::FileWave, perl(1), festival(1), Festival Documentation
| speech_pm documentation | Contained in the speech_pm distribution. |
use Speech::Festival; package Speech::Festival::Synthesiser; use strict "subs"; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw( ); @ISA = qw(Speech::Festival); sub new { my ($class, $args) = @_; my ($host) = $$args{-host} || "localhost"; my ($port) = $$args{-port} || 1314; my ($self) = Speech::Festival->new($host, $port); bless $self, $class; } sub set { my ($self, $key, $val) = @_; my ($host, $port, $s, $props) = @$self; $$props{$key} = $val; } sub start { my ($self) = @_; my ($host, $port, $s, $props) = @$self; my ($res) = Speech::Festival::conn($self); print "connected\n"; if ($res) { request $self "(Parameter.set 'Wavefiletype 'riff)", \&shandler; request $self "(tts_return_to_client)", \&shandler; } $res; } sub stop { my ($self) = @_; Speech::Festival::disconnect($self); } sub wavetype { my ($self, $waveimp, @args) = @_; if ($waveimp eq 'Audio::FileWave' && $#args < 0) { @args = ("riff"); } $self->set('WaveImp', $waveimp); $self->set('WaveArgs', [@args]); eval "use $waveimp;"; die $@ if $@; } sub voice_list { my ($self) = @_; my (@res) = (); request $self "(voice.list)", \&ret_lp_handler, \@res; my ($scheme) = Speech::Festival::parse_scheme($res[0]); # @res = split(/\s+/, ($res[0] =~ /\(\s*(.*?)\s*\)/)[0]); return @$scheme; } sub voice { my ($self, $voice) = @_; return request $self "(voice_$voice)", \&shandler; } sub voice_description { my ($self, $voice) = @_; my ($res) = []; request $self "(voice.description '$voice)", \&ret_lp_handler, $res; return Speech::Festival::parse_scheme($$res[0]); } sub speak { my ($self, $text) = @_; my ($host, $port, $s, $props) = @$self; my ($imp, $args) = ( $$props{WaveImp}, $$props{WaveArgs} ); $text =~ s/\\/\\\\/g; $text =~ s/"/\\"/g; my ($scheme) = '(tts_text "' . $text . '" "text")'; my ($n) = request $self $scheme, \&whandler, $imp, $args; $n-- if $n>0; return $n; } sub synth_description { my ($self) = @_; my ($host, $port, $s, $props) = @$self; my ($imp, $args) = ( $$props{WaveImp}, $$props{WaveArgs} ); my ($n) = request $self '(intro)', \&whandler, $imp, $args; $n-- if $n>0; return $n; } sub shandler { my ($type, $data, @info) = @_; chomp $data; print "shandler got $type:",substr($data,0,10),"\n" if defined($main::verbose) && $main::verbose>0; } sub whandler { my ($type, $data, $imp, $args) = @_; chomp $data; print "whandler got $type:",substr($data,0,10),"\n" if defined($main::verbose) && $main::verbose>0; if ($type eq $Speech::Festival::WAVE) { my ($wave) = $imp->new($data, @$args); play $wave; } } sub ret_lp_handler { my ($type, $data, $res) = @_; chomp $data; print "ret_lp_handler got $type:",substr($data,0,10),"\n" if defined($main::verbose) && $main::verbose>0; if ($type eq $Speech::Festival::SCHEME) { push(@$res, $data); } } 1; __END__