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

Re: [MacPerl] MacPerl sings a 'Camptown Races' in its native language, almost



Now, of course, the song, "The ghost of Brian Foster," from the 
new Squirrel Nut Zippers CD, makes sense with its line, 
"Camptown ladies *never* sang all the doo dah day. Oh, no no."

Xah Lee (and others) asked,
>Yes, someone please make it sing Daisy.

This was also the first thing I thought of when I saw the code come 
across the list.  Here's a cut at it.  The melody has sharps in it, 
so I added the ability for the code to handle accidentals.

-Charles <albrecht@gate.net>


#!perl
# Author: David Seay <http://www.mastercall.com/g-s>
# Modifed by Charles Albrecht to add accidentals & sing "Daisy Bell"
#
# Daisy Bell (A Bicycle Built for Two), Henry Darce, 1892

use Mac::Speech;

$noteNames =    "c  d  e  f  g  a  b  C  D  E  F  G  A  B  C1";
$scalePitches = "48,50,52,53,55,57,59,60,62,64,65,67,69,71,72";
@noteNames = split("  ",$noteNames);
@scalePitches = split(",",$scalePitches);
$pitches = @scalePitches;
for ($p = 0; $p < $pitches; $p++) {
	$pitch{$noteNames[$p]} = $scalePitches[$p];
}

$tempo = 85000; # increase the value if song is too fast 
                # or ends of words are clipped

# NOTE DURATIONS
$dur{e}   = .5;   # eighth note
$dur{de}  = .75;  # dotted eighth note
$dur{q}   = 1;    # quarter note
$dur{dq}  = 1.5;  # dotted quarter note
$dur{h}   = 2;    # half note
$dur{he}  = 2.5;  # half note + an eighth
$dur{dh}  = 3;    # dotted half note
$dur{dhe} = 3.5;  # dotted half note + an eighth
$dur{w}   = 4;    # whole note

# ACCIDENTALS
$acc{s} = 1;      # sharp
$acc{n} = 0;      # natural
$acc{f} = -1;     # flat


# FORMAT FOR '$song' = syllable pitch duration
$song = ". c n h,"; # helps reduce sluggishness of first note
$song.= "daay A s dh, zeee G n dh, daay D s dh, zeee a s dh,";
$song.= "give c n q, me d n q, your d s q, aaan c n h, sir d s q, doooo a s w,";
$song.= "I'm F n dh, halff A s dh, craay G n dh, zeee D s dh,";
$song.= "alll c n q, for d n q, the d s q, love f n h, of g n q, you f n w,";

$song.= "it g n q, won't g s q, be g n q, uh f n q, sty a s h, lish g n q,";
$song.= "mare f n q, ridge d s w, ";
$song.= "I f n q, can't g n h, uh d s q, ford c n h,";
$song.= "uh d s q, care c n q, ridge a s w,";
$song.= "but a s q, you'll d s h, look g n q, sweet f n q, . c n h,";
$song.= "upon d s h, the g n q, seat f n q, of g n e, uh g s e,";
$song.= "buyy a s q, sick g n q, ul d s q, built f n h, for a s q, two d s w";

@song = split(",",$song);
$songNotes = @song;

$count = CountVoices();
for ($i = 0; $i++ < $count; ) {
 	$voice = GetIndVoice($i);
 	$desc  = ${GetVoiceDescription($voice)};
 	# some voices won't change pitch
 	# try 'Zarvox' or 'Pipe Organ' or 'Cellos' or 'Bad News'
	if ($desc =~ /Zarvox/) {
		$channel = NewSpeechChannel($voice)         or die $^E;

		for ($n = 0; $n < $songNotes; $n++) {
			($word,$note,$sharp,$dur) = split(" ",$song[$n]);

			SetSpeechPitch $channel, $pitch{$note}+$acc{$sharp};
			SpeakText $channel, $word               or die $^E;
			$d = int($tempo * $dur{$dur});
			for ($w = 0; $w < $d; $w++) { }
		}
		DisposeSpeechChannel $channel;
	}
}
__END__



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch