AppleScript 脚本让 Mac 唱生日快乐歌
Lucifr 家中有个传统,每个家庭成员的生日都要买个蛋糕,然后全家围坐唱“祝你生日快乐”来对寿星表示祝贺(寿星本人也会像胖虎一样唱“祝我生日快乐”囧)。看来现在又多了个很 geek 的选项:让 Mac 来唱生日快乐歌。
方法如下:
- 打开 AppleScript Editor.app(在“应用程序” ->“实用工具”里),粘贴以下代码:
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 "Victoria" speaking rate speakingRate modulation 0
end repeat
-
现在点一下 Run 这个按钮,你应该能听到 Mac 在用“优美的声线”在给你唱歌了。这里
firstName
和lastName
被设置为当前用户的名和姓。当然你也可以把前三行换成下面这样来自己指定姓名:set firstName to "Lucifr" set lastName to "Liu"
-
此外如果对这个声音不感冒,可以修改倒数第二行的
Victoria
来指定用别的嗓音来唱,比如Bad News
、Bahh
什么的(笑)。自己到“系统选项”->“语音”->“文本至语音”->“系统嗓音”->“自定”里去找一个吧,各种性别和国籍,相信可以满足不同的取向和需求(有些太独特的需要单独下载)。
-
修改满意之后,我们可以把这个脚本起个名字保存一下。为了能在某人生日时自动播放给她/他个惊喜,我们再打开 iCal,设置个提醒:
-
收工~给你的朋友一个惊
吓喜去吧~
via Mac OS X Hints