[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Clipboard Talker



I use the following program to listen to my email, at least the part I have
copied to the clipboard. The Mac won't shut up when 'cmd period' has been
typed so a routine has been added to enable that.

--------------

#!perl5

# "Clip Talk" by David Seay
# by David Seay
#
# 1) Copy a selection of text from any application.
# 2) Run this program to hear it spoken.
# 3) Type 'cmd period' to stop speech and exit.
#

package Main;
use Mac::Speech;

use Mac::Events;
use Mac::Events qw(@Event $CurrentEvent);
use Mac::LowMem;

$Event[keyDown] = \&key_down;
&MacPerl::LoadExternals("clipboard.XFCN");
$clip = &Main::Clipboard();

&add_pauses_between_sentences;
&give_speech;


sub add_pauses_between_sentences {
	$clip =~ s/\n/ /g;
	$clip =~ s/  / /g;
	$clip =~ s/>//g;
	$clip =~ s/<//g;
	$clip =~ s/\! /\!\n/g;
	$clip =~ s/\? /\?\n/g;
	$clip =~ s/\. /\.\n/g;
}

sub give_speech {
	@speech = split(/\n/,$clip);
	if (! $speech[0]) {
		$speech[0] = "The clipboard has nothing to say."
	}
	if (! $speaker) { $speaker = "Fred" }
	$voice = $Voice{$speaker};
	$channel = NewSpeechChannel($voice) or die $^E;
	for $z (0..$#speech) {
		$speech = $speech[$z];
		SpeakText($channel, $speech) || die $^E;
 	while (SpeechBusy()) { WaitNextEvent() }
	}
	DisposeSpeechChannel($channel);
}

sub key_down {
	my($ev) = @_;
	$k = chr($ev->character);
	if (($CurrentEvent->modifiers & 256) == 256 && $k eq ".") {
		StopSpeech $channel or die $^E;
		DisposeSpeechChannel($channel);
		exit(0);
	}
}



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org