Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Make the computer sing happy birthday System
Here's a way to use AppleScript and the 'say' command to have the computer sing happy birthday to you. Enjoy!
set currentUser to long user name of (get system info)
set firstName to first word of currentUser
set lastName to last word of currentUser

set noteValues to {56, 56, 58, 56, 61, 60, 50, 56, 56, 58, 56, 63, 61, 50, 56, 56, 68, 65, 61, 60, 58, 50, 66, 66, 65, 61, 63, 61} -- F
-- set noteValues to {65, 65, 67, 65, 70, 69, 60, 65, 65, 67, 65, 72, 70, 60, 65, 65, 77, 74, 70, 69, 67, 60, 75, 75, 74, 70, 72, 70} -- D
-- set noteValues to {55, 55, 57, 55, 60, 59, 50, 55, 55, 57, 55, 62, 60, 50, 55, 55, 67, 64, 60, 59, 57, 50, 65, 65, 64, 60, 62, 60} -- E

set syllables to {"hap", "p", "birth", "day", "to", "you", "[[slnc 500]]", "hap", "p", "birth", "day", "to", "you", "[[slnc 500]]", "hap", "p", "birth", "day", "dear", firstName, lastName, "[[slnc 500]]", "hap", "p", "birth", "day", "to", "you"}

repeat with i from 1 to the length of noteValues
	set thisValue to item i of noteValues
	set thisSyllable to item i of syllables
	if length of thisSyllable is less than 3 then
		set speakingRate to 220
	else
		set speakingRate to 100
	end if
	say thisSyllable pitch thisValue using "Cellos" speaking rate speakingRate modulation 0
end repeat

[crarko adds: Works as described. From the mind of Sal Soghoian. For extra credit tie it to an iCal reminder of a person's birthday, and see if you can put that person's name into the firstname and lastname variables and have it autoplay. A similar hint was also submitted by user 'Nyhthawk,' and I want to acknowledge that as well. Thanks!]
    •    
  • Currently 4.17 / 5
  You rated: 5 / 5 (12 votes cast)
 
[10,481 views]  

Make the computer sing happy birthday | 10 comments | Create New Account
Click here to return to the 'Make the computer sing happy birthday' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make the computer sing happy birthday
Authored by: Pete1945 on Feb 06, '12 08:25:58AM

I couldn't make this work. Got the error "Expected end of line, etc. but found identifier" at the word "Pitch" when I compile or save it. Running 10.5.8 PowerPC.



[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: Sesquipedalian on Feb 06, '12 08:47:45AM

This doesn't seem to work with the new voices made available in Lion. Tom, Samantha, etc., apparently ignore the pitch and modulation options of the say command. So to make this work, choose one of the older voices like Alex, Vicki, or Cellos.



[ Reply to This | # ]
Make the computer sing unhappy birthday
Authored by: MickPunk on Feb 06, '12 08:53:16AM

Just don't do that in public or you may be engaging in copyright infringement!

http://www.unhappybirthday.com



[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: gmachen on Feb 06, '12 10:34:26AM
say thisSyllable pitch thisValue using "Cellos" speaking rate speakingRate modulation 0
Syntax Error: "Expected end of line , etc. but found identifier"

....at "pitch"

Leopard 10.5.8

[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: auco on Feb 06, '12 10:43:30AM

if you paste it somewhere as a string you have to escape the quotes: \"Cellos\"

Edited on Feb 06, '12 10:43:50AM by auco



[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: gmachen on Feb 06, '12 10:49:10AM
\"Cellos\"
Made no difference; same error.

[ Reply to This | # ]
Re: Make the computer sing happy birthday
Authored by: Uncle Asad on Feb 06, '12 03:14:01PM

The "pitch", "speaking rate", and "modulation" parameters for the "say" command aren't present in the Standard Additions dictionary in 10.5 (use the Library window of Script Editor to access that dictionary); they must have been added in 10.6 or later.



[ Reply to This | # ]
Oh sure
Authored by: jethro1138 on Feb 06, '12 10:35:25AM

Oh sure, post this a couple of days after my birthday!



[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: chancer on Feb 06, '12 12:10:26PM
How did you know? It is my birthday today! Thank you! It sounds best by far with Cellos.
Edited on Feb 06, '12 12:12:13PM by chancer


[ Reply to This | # ]
Make the computer sing happy birthday
Authored by: dzurn on Feb 08, '12 01:29:18PM
Now that's something you don't hear every day.
---
Madness takes its toll.
Please have exact change.


[ Reply to This | # ]