Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Interactive Text-to-Speech (Windows, Perl) (See related posts)

This script calls the Windows OLE for the built in TTS. Type what you want the computer to say at the prompt and hit enter. To quit type ":q" (minus the quotation marks).


use Win32::OLE qw( EVENTS );

get_text();

sub get_text{
	$output_speech = <STDIN>;
	chomp($output_speech);
	if($output_speech ne ":q"){
		say_this();
		get_text();
	}
}

sub say_this{
	my $myTTS = new Win32::OLE( "Sapi.SpVoice" ); 
	$myTTS->Speak( "$output_speech" );
	while( $myTTS->{Speaking} )
	{
		Win32::OLE->SpinMessageLoop();
		Win32::Sleep( 100 );
	}
}

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts