The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Speech::Synthesis - A generic interface for different Text To Speech Engines

VERSION

This is Speech::Synthesis 0.03

SYNOPSIS

    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");
    }

DESCRIPTION

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!

CLASS METHODS

@engines = Speech::Synthesis->InstalledEngines()

This class method returns a list of installed Speech Engines. Depending on your platform, it may return one or more of the following:

'MSAgent' (Win32 only)
'SAPI4' (Win32 only)
'SAPI5' (Win32 only)
'MacSpeech' (OS X only)
'Festival' (only connects to the default port on localhost)

@langs = Speech::Synthesis->InstalledLanguages(%params)

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:

engine

This can be one of the values that InstalledEngines returns

host

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.

port

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.

@voices = Speech::Synthesis->InstalledVoices(%options)

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:

engine

This takes an engine name as used in InstalledEngines (mandatory).

host

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.

port

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.

language

This takes one or more of the language values as returned by InstalledLanguages()

gender

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.

@avatars = Speech::Synthesis->InstalledAvatars(engine => $engine)

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.

INSTANCE METHODS

$ss = Speech::Synthesis->new(%options)

This is the constructor. Parameters can be supplied using key/value combinations. Valid parameters are:

engine

The value for the 'engine' key can be one of the speech engine values described in the InstalledEngines class method.

host

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.

port

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.

voice

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.

language

This parameter is mandatory when you specify 'MSAgent' as the engine. It will be ignored otherwise

avatar

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.

async

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)

$o = $ss->getobject()

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)

$ss->voice($id)

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.

$ss->speak($string)

This method speaks the $string using the selected engine and the selected voice.

BUGS AND CAVEATS

The working of asynchronous speech doesn't work on MSAgent and SAPI5.

AUTHOR

Jouke Visser, <jouke@pvoice.org>

BUGS

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.

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

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.