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

[MacPerl] Jokers



#!perl

# "Jokers" v1.5 (used to be "Stand-up Comic")
#  by David Seay <g-s@navix.net>
#
# November 1999
#

use Mac::Speech;

# Substitute your own jokes into $script
# Put "RESPONSE" on a line by itself after each joke
$script = <<"EOF";
Ethyl: How many guitar players does it take to change a light bulb?
Fred: I don't know. How many guitar players does It take to change a light
bulb?
Ethyl: 5! 1 to change the light bulb and 4 to sit back and say, He ain't so
Hot!
RESPONSE
Ricky: How many bluegrass musicians does it take to change a light bulb?
Lucy: I don't know. How many bluegrass musicians does It take to change a
light bulb?
Ricky: 5! 1 to change the light bulb and 4 to complain about it being electric!
RESPONSE
Fred: How many drummers does it take to change a light bulb?
Ricky: I don't know. How many drummers does It take to change a light bulb?
Fred: None! They have a machine that does that now.
RESPONSE

EOF

@lines = split(/\n/, $script);

$responses = <<"EOF";
&oneLiner("Princess: Huh? I don't get it.");
&oneLiner("Hysterical: Ha ha ha ha he he he he ho ho ho ho ho ho ha ha ha
ha ha ha?");
&oneLiner("Fred: I've heard it before.");
&oneLiner("Deranged: ha ha ha ha");
&applause1;
&applause2;
&boo;
&group_laughter;
&group_laughter;
&group_laughter;
&ha_ha;
&zonked_out_geese;
EOF

@responses = split(/\;/, $responses);
chomp(@responses);

&get_audition_list;
&cast_parts;
&read_through;
&wrap_up;

exit(0);

sub get_audition_list {
	$count = CountVoices();
	for $i (1..$count) {
	 	$voice = GetIndVoice($i);
	 	$desc  = ${GetVoiceDescription($voice)};
	 	$nameLength = ord(substr($desc,16,1));
	 	$name = substr($desc,17,$nameLength);
	 	$speaker{$name} = "";
	 	$options[$i - 1] = $name;
	}
	@options = sort @options;
}

sub cast_parts {
	for $i (1..$#lines) {
		if ($lines[$i] =~ /RESPONSE/) { next }
		($character,$speech) = split(/:/, $lines[$i]);
		$part{$character} = "";
	}
	print"\n";
	foreach $c (sort keys %part) {
		$prompt = "Select from the list for the part of \'$c\'.";
		$choice = MacPerl::Pick("$prompt",@options);
		if ($choice eq "") { exit(0) }
		print "\'$choice\' will speak the part of \'$c\'\n";

		$cast{$c} = $choice;
 		for $count (0..$#options) {
			if ($options[$count] eq $choice) {
 				$options[$count] = "";
 				@options = sort @options;
 				shift @options;
				last;
			}
		}
	}
}

sub read_through {
	for $i (0..$#lines) {
		if ($lines[$i] =~ /RESPONSE/) {
			&react;
		} else {
			($character,$speech) = split(/:/, $lines[$i]);
			$voice = $Voice{$cast{$character}};
			$channel = NewSpeechChannel($voice) or die $^E;
			SpeakText($channel, $speech) || die $^E;
		}
		while (SpeechBusy()) {}
	}
}

sub react {
	$reaction .= $responses[int(rand ($#responses + 1))];
	eval $reaction;
}

sub oneLiner {
	($speaker,$speech) = split(/: /,@_[0],2);
	$channel = NewSpeechChannel ($Voice{$speaker}) or die $^E;
	SpeakText $channel, $speech;
}

sub group_laughter {
	@words = split(",","ha ha ,hey hey ,ho ho ,ha ha ,he he ");
	@speakers = split(",","Fred,Kathy,Hysterical,Zarvox");
	$voices = 6;
	for $v (0..$voices) {
		$phrase = "ha ha ";
		for $w (0..6) { $phrase .= $words[int(rand ($#words + 1))] }
		$channel[$v] = NewSpeechChannel
			($Voice{$speakers[int(rand ($#speakers + 1))]}) or
die $^E;
		SpeakText $channel[$v], $phrase;
	}
	while (SpeechBusy()) {
		$v = int(rand ($voices));
		$pitch = int(rand (20)) + 48;
		SetSpeechPitch $channel[$v], $pitch;
  	 	select(undef, undef, undef, .1);
	}
}

sub applause1 {
	$speech = "ik" x 20;
	for $v (0..7) {
		$channel[$v] = NewSpeechChannel ($Voice{"Kathy"}) or die $^E;
		SetSpeechPitch $channel[$v], ($v*2.5);
		SpeakText $channel[$v], $speech;
	 	select(undef, undef, undef, .2);
	}
}

sub applause2 {
	@speakers = split(",","Ralph");
	$voices = 5;
	$pitch = 5;
	for $v (0..$voices) {
		$channel[$v] = NewSpeechChannel
			($Voice{$speakers[int(rand ($#speakers + 1))]}) or
die $^E;
 		$pitch = $pitch + 2;
 		SetSpeechPitch $channel[$v], $pitch;
	}
	for $k (0..8) {
		for $v (0..$voices) {
			StopSpeech $channel[$v] or die $^E;
			SpeakText $channel[$v], "k";
		}
	}
	for $v (0..$voices) {
		StopSpeech $channel[$v] or die $^E;
	}
}


sub ha_ha {
	$channel = NewSpeechChannel ($Voice{"Good News"}) or die $^E;
	SetSpeechPitch $channel, 64;
	SpeakText $channel, "ha";
	select(undef, undef, undef, .3);
	SetSpeechPitch $channel, 60;
	SpeakText $channel, "ha";
	select(undef, undef, undef, .5);
	StopSpeech $channel or die $^E;
}


sub boo {
	@speakers = split(",","Fred,Kathy,Junior,Zarvox,Pipe Organ");
	$voices = 8;
	for $i (0..4) {
		for $v (0..$#speakers) {
			$channel[$v] = NewSpeechChannel
($Voice{$speakers[$v]}) or die $^E;
			SpeakText $channel[$v], "Boo, Boo";
			$pitch = int(rand (7)) + 48;
			SetSpeechPitch $channel[$v], $pitch;
		 	select(undef, undef, undef, .3);
		}
	}
}

sub zonked_out_geese {
	@speakers = split(",","Ralph");
	$voices = 5;
	$pitch = 65;
	for $v (0..$voices) {
		$channel[$v] = NewSpeechChannel
			($Voice{$speakers[int(rand ($#speakers + 1))]}) or
die $^E;
 		$pitch = $pitch + 2;
 		SetSpeechPitch $channel[$v], $pitch;
	}
	for $k (0..8) {
		for $v (0..$voices) {
			StopSpeech $channel[$v] or die $^E;
			SpeakText $channel[$v], "k";
		}
	}
	for $v (0..$voices) {
		StopSpeech $channel[$v] or die $^E;
	}
}

sub wrap_up {
	while (SpeechBusy()) {}
	DisposeSpeechChannel $channel or die $^E if $channel;
	for $v (0..$voices) {
		DisposeSpeechChannel $channel[$v] or die $^E if $channel[$v];
	}
}



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