利用 AVSpeechSynthesisVoice 發出有趣的說話聲音
Published in
Apr 20, 2023
從設定 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
公主,明星的聲音。