Speech::Synthesis - A generic interface for different Text To Speech Engines
This is Speech::Synthesis 0.03
use Speech::Synthesis; my $engine = 'SAPI5'; # or 'SAPI4', 'MSAgent', 'MacSpeech' or 'Festival' my @voices = Speech::Synthesis->InstalledVoices(engine => $engine); my @avatars = Speech::Synthesis->InstalledAvatars(engine => $engine); foreach my $voice (@voices) { my %params = ( engine => $engine, avatar => undef, language => $voice->{language}, voice => $voice->{id}, async => 0 ); my $ss = Speech::Synthesis->new( %params ); $ss->speak($voice->{description}||"test"); }
There are all sorts of Speech Synthesis (or Text To Speech) modules on CPAN, supporting all kinds of different Speech APIs. However, each of these modules has its own functions and methods, and writing platform-independent code using these modules is a hell. Therefore Speech::Synthesis provides one API that supports many different speech APIs, like Mac::Speech on OS X, Win32::SAPI4, Win32::SAPI5 and Win32::MSAgent on Win32 platforms, and Festival::Client::Async on all other platforms. You never have to worry about their different ways: just use Speech::Synthesis!
This class method returns a list of installed Speech Engines. Depending on your platform, it may return one or more of the following:
This method queries the installed languages for the specified engine (see 'InstalledEngines'). The data that is returned uses the ISO 3166-1 conventions. This specification uses a two-letter, capitalized code to identify a specific country. By catenating a language designator with an underscore character and a regional designator, you get a designator that identifies the locale for a specific language and country. It could return a list like ('en_US', 'en_GB', 'fr_CA', 'nl_NL'). Festival may return only a two letter language code, since the countrycode cannot always be determined. Valid parameters that you may provide as a hash to this method are:
This can be one of the values that InstalledEngines returns
This is an optional parameter, which is only used for the 'Festival' engine. It represents the host that the festival server is running on. If you don't provide it, Speech::Synthesis assumes it's localhost.
This is an optional parameter, which is only used for the 'Festival' engine. It represents the port that the festival server is running on. If you don't provide it, Speech::Synthesis assumes it's 1319.
This method queries the installed voices for the Speech Synthesis object. You can supply one or more options, which will have a filtering effect on the returned voices. These options are:
This takes an engine name as used in InstalledEngines (mandatory).
This takes one or more of the language values as returned by InstalledLanguages()
This parameter can be one of the following: 'male', 'female' or 'neutral'.
The voices array that this method returns is an array of hashrefs. Each hashref contains at least the following keys: 'id', 'name', 'description', 'language', 'gender', 'age'. It may return more keys, depending on what the selected engine supports. If a key has an undefined value, it simply isn't available.
This class method currently only works for the 'MSAgent' engine (so that's the only value for the $engine that will actually return anything), and it will return a list of avatars (MS Agent Characters) that are currently installed.
This is the constructor. Parameters can be supplied using key/value combinations. Valid parameters are:
The value for the 'engine' key can be one of the speech engine values described in the InstalledEngines class method.
The value of the 'voice' key can be one of the 'id' values as defined in the array of hashrefs that the InstalledVoices method returns.
This parameter is mandatory when you specify 'MSAgent' as the engine. It will be ignored otherwise
This parameter is mandatory when you specify 'MSAgent' as the engine. It will be ignored otherwise. It is the avatar (or Agent Character) that will show up on your desktop and "speak" the text for you. It might be used for other engines in the future.
This parameter defines wether we will wait until speaking finishes or not. By default, async = 1. If you want your code to wait until it finishes speaking, set it to 0. (not supported for MSAgent and SAPI4)
This method returns the original Perl object that the Speech::Synthesis module uses at that very moment. It doesn't support Mac::Speech (since that module doesn't use objects)
This method gets or sets the id of the voice. This is the same 'id' as used in the voices array of hashrefs in the InstalledVoices method.
This method speaks the $string using the selected engine and the selected voice.
The working of asynchronous speech doesn't work on MSAgent and SAPI5.
Jouke Visser, <jouke@pvoice.org>
<jouke@pvoice.org>
Please report any bugs or feature requests to bug-speech-synthesis@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Speech-Synthesis. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-speech-synthesis@rt.cpan.org
Copyright 2005 Jouke Visser, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Speech::Synthesis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Speech::Synthesis
CPAN shell
perl -MCPAN -e shell install Speech::Synthesis
For more information on module installation, please visit the detailed CPAN module installation guide.