萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 手機 >  >> 手機應用 >> iPhone

Mac 終端機 AppleScript 讓 Siri 唱生日歌:自訂姓名與聲音完整腳本

Mac 內建「腳本編輯器」執行 AppleScript,可讓系統語音合成(Siri 前身)唱生日歌,支援自訂姓名、語速、音高、聲音人格。

操作步驟

1. 開啟腳本編輯器

Spotlight 搜尋「Script Editor」或「腳本編輯器」開啟。

2. 貼上完整 AppleScript 程式碼

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

3. 執行腳本

點選工具列「執行」(▶️)按鈕,Mac 即刻唱出生日歌。

自訂客製化

指定姓名(不讀取系統帳號)

將前三行替換為:

set firstName to "David"
set lastName to "Chen"

建議使用英文名,中文發音在舊版語音引擎可能不準。

更換聲音人格

修改倒數第二行 using "Victoria":

  • 系統偏好設定 → 「口述與語音」→「系統聲音」→「自訂」可預聽下載
  • 常用:Alex(美式男)、Victoria(美式女)、Ting-Ting(中文女)、Sin-Ji(港式女)、Mei-Jia(台式女)

調整音高與速度

  • noteValues 陣列為 MIDI 音高數值(60 = 中央 C),三組預設對應 F/D/E 大調
  • speakingRate:短音節 220、長音節 100,可自行微調
  • [[slnc 500]]:500ms 靜默間隔,可調整節奏

進階應用

  • 存為 .scpt/.app 檔,雙擊即唱,適合派對驚喜
  • 搭配 Automator/捷徑指令設定快捷鍵/語音指令觸發
  • 導出音訊檔:終端機 say -o birthday.aiff -f script.txt

幾行代碼,讓 Mac 成為最貼心的生日歌手。

copyright © 萬盛學電腦網 all rights reserved