利用 AVSpeechSynthesisVoice 發出有趣的說話聲音

從設定 App 的語音內容 > 聲音下我們可以找到許多有趣的聲音。有些聽起來像低聲說話,有些像機器人,有些像好聽的歌唱。

我們自己開發的 App 也能利用 AVSpeechSynthesisVoice 發出有趣的聲音,只要在產生 AVSpeechSynthesisVoice 時傳入聲音的 id。

若是不清楚聲音的 id,可先用迴圈列出 AVSpeechSynthesisVoice 的清單,印出每一種聲音的 id。

for voice in AVSpeechSynthesisVoice.speechVoices() {
print(voice.name, voice.identifier)
}

以下為彼得潘試聽後,整理出一些有趣的聲音 id。

  • com.apple.speech.synthesis.voice.Whisper

低聲說話,氣音。

import AVFAudio

let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "Dreams do come true, if only we wish hard enough.")
utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.speech.synthesis.voice.Whisper")
synthesizer.speak(utterance)
  • com.apple.speech.synthesis.voice.Trinoids & com.apple.speech.synthesis.voice.Zarvox

機器人的聲音。

  • com.apple.speech.synthesis.voice.Organ

類似管風琴唱歌的聲音。

  • com.apple.speech.synthesis.voice.Cellos

類似大提琴唱歌的聲音。

  • com.apple.speech.synthesis.voice.Bubbles

搭配泡泡的聲音。

  • com.apple.speech.synthesis.voice.Bells

類似鐘聲的聲音。

  • com.apple.speech.synthesis.voice.Hysterical

歇斯底里,小丑的聲音。

  • com.apple.speech.synthesis.voice.GoodNews

好消息的唱歌聲音。

  • com.apple.speech.synthesis.voice.BadNews

壞消息的唱歌聲音。

  • com.apple.speech.synthesis.voice.Princess

公主,明星的聲音。

--

--

彼得潘的 iOS App Neverland
彼得潘的 Swift iOS App 開發問題解答集

彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,彼得潘的 Swift 程式設計入門,App程式設計入門作者,http://apppeterpan.strikingly.com