Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Changing the voice in MS Text to speech?

by Massyn (Hermit)
on Sep 05, 2003 at 10:36 UTC ( [id://289156]=perlquestion: print w/replies, xml ) Need Help??

Massyn has asked for the wisdom of the Perl Monks concerning the following question:

#!/fellow/monks.pl

This code works... I just want to change the voice to one of the more realistic ones. I don't like Microsoft Sam that much.. Any ideas what I need to change? I do have the Lernout & Haupsie Truvoice engine installed

sub talk { local $txt = $_[0]; use Win32::OLE; local $voice = Win32::OLE->new("Speech.VoiceText") or die("TTS + failed"); $voice->Register("", "$0"); $voice->{Enabled} = 1; # optional $voice->Speak($txt, 1); while ($voice->IsSpeaking()) { sleep 1; } }

Thanks!

#!/massyn.pl

Don't -- me without telling me why. If you asked a stupid question, I wouldn't down vote you.

Replies are listed 'Best First'.
Re: Changing the voice in MS Text to speech?
by Jouke (Curate) on Sep 08, 2003 at 10:09 UTC
    In the latest version of pVoice, which you can download at http://opensource.pvoice.org these days, I'm using something like this to select the speechengine:
    #!/usr/bin/perl use strict; use warnings; use Win32::SAPI4; use Win32::Locale; use Locale::Country; use Locale::Language; # This hashref represents some of the possible LanguageIDs that MS use +s my $Languages = {'Arabic' => 0x0401, 'Basque' => 0x042D, 'Chinese (Simplified)' => 0x0804, 'Chinese (Traditional)' => 0x0404, 'Croatian' => 0x041A, 'Czech' => 0x0405, 'Danish' => 0x0406, 'Dutch' => 0x0413, 'English (British)' => 0x0809, 'English (US)' => 0x0409, 'Finnish' => 0x040B, 'French' => 0x040C, 'German' => 0x0407, 'Greek' => 0x0408, 'Hebrew' => 0x040D, 'Hungarian' => 0x040E, 'Italian' => 0x0410, 'Japanese' => 0x0411, 'Korean' => 0x0412, 'Norwegian' => 0x0414, 'Polish' => 0x0415, 'Portuguese (Portugal)' => 0x0816, 'Portuguese (Brazil)' => 0x0416, 'Romanian' => 0x0418, 'Russian' => 0x0419, 'Slovakian' => 0x041B, 'Slovenian' => 0x0424, 'Spanish' => 0x0C0A, 'Swedish' => 0x041D, 'Thai' => 0x041E, 'Turkish' => 0x041F}; # I'm using my SAPI4 module here, you could also create the # voicetext object yourself. my $vt = Win32::SAPI4::VoiceText->new() || die "Can't start VoiceText" +; # Get All available languages from installed speechengines my @alllangs = getlanguages($vt); print join("\n", @alllangs); # Get all available voices from a specific language, replace # 'Dutch' with the hashkey of your choice (see the $Languages # hashref above) my $language = languageid2language($Languages->{'Dutch'}); my @allvoices =getvoices($language, $vt); print "\n\n", join ("\n", @allvoices); # Say that one of the voices is named 'Adult Female #1 Dutch (L&H)' # which is one of the dutch voices I have installed for (my $i=1; $i <= $vt->CountEngines; $i++) { select($i) if $vt->ModeName($i) eq 'Adult Female #1 Dutch (L&H)'; } #--------------------------------------------------------------------- +- # This sub returns the names of the installed voices sub getvoices { my $language = shift; my $v = shift; my @r; # We wander through the number of installed engines for (my $i=1; $i <= $v->CountEngines; $i++) { my ($t1, $t2) = split(/-/,Win32::Locale::get_language($v->Lang +uageID($i))); push @r, $v->ModeName($i) if $language eq code2language($t1)." + (".code2country($t2).")"; } return @r; } #--------------------------------------------------------------------- +- # This sub returns the names of the installed languages sub getlanguages { my $v = shift; my %r; # Also here we browse through the installed engines for (my $i=1; $i <= $v->CountEngines; $i++) { my ($t1, $t2) = split(/-/,Win32::Locale::get_language($v->Lang +uageID($i))); $r{code2language($t1)." (".code2country($t2).")"}++; } return keys %r; } #--------------------------------------------------------------------- +- # This sub returns a readable language for the given $languageid sub languageid2language { my $languageid = shift; my ($t1, $t2) = split(/-/,Win32::Locale::get_language($languageid) +); return code2language($t1)." (".code2country($t2).")"; }


    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
Re: Changing the voice in MS Text to speech?
by Mr. Muskrat (Canon) on Sep 05, 2003 at 16:35 UTC

    Download and install the latest Microsoft Speech SDK (currently it's Microsoft Speech SDK 5.1).

    use Win32::OLE; talk("Hello user.", "microsoft sam"); talk("I like you."); # microsoft mary is the default for SAPI.SpVoice talk("Goodbye!", "microsoft mike"); sub talk { my $text = shift; my $voice = shift; my $speech = Win32::OLE->new("SAPI.SpVoice") or die("TTS failed"); $speech->{voice} = $speech->GetVoices("name = $voice")->Item(0) if $ +voice; $speech->{rate} = -2; # speaking rate has a valid range of -10..10 $speech->Speak($text); }

Re: Changing the voice in MS Text to speech?
by PodMaster (Abbot) on Sep 05, 2003 at 15:23 UTC
    Check out the guts of Win32::MSAgent, especially
    sub Voice { my $self = shift; my $language = shift; my $voice = shift; $self->{_Characters}->{LanguageID} = $Languages->{$language}; $self->{_Characters}->{TTSModeID} = $Voices->{$language}->{$voice} +; }
    and the associated Voices/Languages hashes
    our $Voices ={'English (US)' => {'Adult Female #1' => '{CA141FD +0-AC7F-11D1-97A3-006008273008}', 'Adult Female #2' => '{CA141FD0- +AC7F-11D1-97A3-006008273009}', 'Adult Male #1' => '{CA141FD0- +AC7F-11D1-97A3-006008273000}', 'Adult Male #2' => '{CA141FD0- +AC7F-11D1-97A3-006008273001}', 'Adult Male #3' => '{CA141FD0- +AC7F-11D1-97A3-006008273002}', 'Adult Male #4' => '{CA141FD0- +AC7F-11D1-97A3-006008273003}', 'Adult Male #5' => '{CA141FD0- +AC7F-11D1-97A3-006008273004}', 'Adult Male #6' => '{CA141FD0- +AC7F-11D1-97A3-006008273005}', 'Adult Male #7' => '{CA141FD0- +AC7F-11D1-97A3-006008273006}', 'Adult Male #8' => '{CA141FD0- +AC7F-11D1-97A3-006008273007}'}, 'English (British)' => {'Carol' => '{227A0E40-A92A- +11d1-B17B-0020AFED142E}', 'Peter' => '{227A0E41-A92A-11 +d1-B17B-0020AFED142E}'}, 'Dutch' => {'Linda' => '{A0DDCA40-A92C-11 +d1-B17B-0020AFED142E}', 'Alexander'=> '{A0DDCA41-A92C-11 +d1-B17B-0020AFED142E}'}, 'French' => {'Véronique'=> '{0879A4E0-A92C-11 +d1-B17B-0020AFED142E}', 'Pierre' => '{0879A4E1-A92C-11 +d1-B17B-0020AFED142E}'}, 'German' => {'Anna' => '{3A1FB760-A92B-11 +d1-B17B-0020AFED142E}', 'Stefan' => '{3A1FB761-A92B-11 +d1-B17B-0020AFED142E}'}, 'Italian' => {'Barbara' => '{7EF71700-A92D-11 +d1-B17B-0020AFED142E}', 'Stefano' => '{7EF71701-A92D-11 +d1-B17B-0020AFED142E}'}, 'Japanese' => {'Naoko' => '{A778E060-A936-11 +d1-B17B-0020AFED142E}', 'Kenji' => '{A778E061-A936-11 +d1-B17B-0020AFED142E}'}, 'Korean' => {'Shin-Ah' => '{12E0B720-A936-11 +d1-B17B-0020AFED142E}', 'Jun-Ho' => '{12E0B721-A936-11 +d1-B17B-0020AFED142E}'}, 'Portuguese (Brazil)' => {'Juliana' => '{8AA08CA0-A1AE-11 +d3-9BC5-00A0C967A2D1}', 'Alexandre'=> '{8AA08CA1-A1AE-11 +d3-9BC5-00A0C967A2D1}'}, 'Russian' => {'Svetlana' => '{06377F80-D48E-11 +d1-B17B-0020AFED142E}', 'Boris' => '{06377F81-D48E-11 +d1-B17B-0020AFED142E}'}, 'Spanish' => {'Carmen' => '{2CE326E0-A935-11 +d1-B17B-0020AFED142E}', 'Julio' => '{2CE326E1-A935-11 +d1-B17B-0020AFED142E}'}}; our $Languages = {'Arabic' => 0x0401, 'Basque' => 0x042D, 'Chinese (Simplified)' => 0x0804, 'Chinese (Traditional)' => 0x0404, 'Croatian' => 0x041A, 'Czech' => 0x0405, 'Danish' => 0x0406, 'Dutch' => 0x0413, 'English (British)' => 0x0809, 'English (US)' => 0x0409, 'Finnish' => 0x040B, 'French' => 0x040C, 'German' => 0x0407, 'Greek' => 0x0408, 'Hebrew' => 0x040D, 'Hungarian' => 0x040E, 'Italian' => 0x0410, 'Japanese' => 0x0411, 'Korean' => 0x0412, 'Norwegian' => 0x0414, 'Polish' => 0x0415, 'Portuguese (Portugal)' => 0x0816, 'Portuguese (Brazil)' => 0x0416, 'Romanian' => 0x0418, 'Russian' => 0x0419, 'Slovakian' => 0x041B, 'Slovenian' => 0x0424, 'Spanish' => 0x0C0A, 'Swedish' => 0x041D, 'Thai' => 0x041E, 'Turkish' => 0x041F};
    Give it a try and see if it runs (i believe/hope all you have to do is set the appropriate values for $voice->{LanguageID} and $voice->{TTSModeID}).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://289156]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found