Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text to speech integrated with perl. 1

Status
Not open for further replies.

jackz15

Programmer
Jun 28, 2006
103
US
I was wondering if it is possible to combine a text to speech program, perhaps the default one on XP, with a perl program, so that the program will read all of the out puts? If possible, can someone tell me how or give me a link?
Thanks
 
Yes, this is possible!

I spend a lot of time investigating new capabilities of Perl and expanding my knowledge. One of my experiments was to get Perl to speak to me out loud!

Here's my code:

Code:
#!/usr/bin/perl -w

use strict;
use warnings;
use Win32::OLE;
use Data::Dumper;
$| = 1;

my $speech = Win32::OLE->new ('SAPI.SpVoice');

my @msg = (
	'Hello world!',
);

foreach (@msg) {
	$speech->Speak ($_,0);
}

my $voices = $speech->GetVoices();
print "Voices: " . Dumper($voices) . "\n";
# $speech->Voice ($speech->GetVoices("Name=Microsoft Mary"))->Item(0);

$speech->Speak ("[URL unfurl="true"]www.microsoft.com",[/URL] 0);

$speech->Speak ("<pitch absmiddle='1'>"
	. "The quick brown fox jumps over the lazy dog.",0);

$speech->Speak ("<pitch absmiddle='10'>"
	. "The quick brown fox jumps over the lazy dog.",0);

$speech->Speak ("<pitch absmiddle='50'>"
	. "The quick brown fox jumps over the lazy dog.",0);

$speech->Speak ("<rate absspeed='10'>"
	. "The quick brown fox jumps over the lazy dog.",0);

$speech->Speak ("<volume level='50'>"
	. "All your <volume level='100'>base</volume> are belong to us.",0);

$speech->WaitUntilDone (-1);
exit;

The commented-out $speech->Voice line would change the voice being used, but only if you've installed new voices. Otherwise you're stuck with Microsoft Sam. I haven't been able to figure out how to install new voices that Perl can use though.

But that should get you started.
 
thanks so much! this looks(no, sounds) awesome! I'm currently implementing this into my code! There is one problem though, for some reason it pauses way too long between empty spaces, setting the rate higher did not seem to help.
 
oh well, there didnt' seem to be a problem with the pause. It was dreadfully slow for the "test" code that i made to see what i needed for my own code. But in my own code, it worked fine.
I have a new problem though, and this is an SQL problem.
My program is basically a study program for vocabulary. You can insert new vocabs with its def, delete vocabs, search vocabs,a listing funtion to list all the vocab(this is ny problem), and there is even a pop quiz function which randomly picks a vocab to quiz the user. Of course with Kirsle's help I managed to make all the outputs voiced. But thats of topic, oh the irony...
now its ok to list all the vocab from the database, if you only have less than 100 so far. But once you get into the 1000s range, it will be ugly and slow. By the way, in my code if you enter '@' it calls for this list.
What i want:
And after @ there should be the vocab that you want to start with, my sql code should be able to select everything AFTER the vocab i entered, and NOT before it. The results must be limited to 50.
I know I could use LIMIT but I'd have to find the row number of the vocab first! And to do that, i'd have to select everything! Is there a way to bypass this?
 
If the Speak call is pausing your program, try changing the 0 to a 1 in the second argument. That way it will speak asynchronously and return immediately, allowing your program to continue in its code (this is especially useful with a GUI as a GUI needs to be updated rapidly).

Make a new topic about your SQL question, since it's not entirely related to text2speech.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top