用AVSpeechSynthesizer唸歌詞
Published in
2 min readDec 30, 2019
唸歌詞: https://streamable.com/adhtn
唸出歌詞的步驟:
1.匯入講話功能: import AVFoundation
2.輸入想唸的歌詞: let 常數= AVSpeechUtterance(string:" 歌詞")
3.調整講話的細節(依喜好增加或省略):
講話的語言(voice):常數.voice = AVSpeechSynthesisVoice(language: "語言代碼")
語言代碼網址:https://gist.github.com/vitoziv/9108407
講話速度(rate):常數.rate = 範圍0-1
講話音調(pitchMultiplier):常數.pitchMultiplier = 範圍0.5-2.0
講話音量(volume):常數.volume = 範圍0-1
4.產生合成器:let synthesizer = AVSpeechSynthesizer()
5.讓合成器講話:synthesizer.speak(常數)
按下play就可以講話了