我使用下面的代碼添加文本到語音功能在我的iOS應用:使用iPhone揚聲器AVSpeechSynthesizer
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker)
try! AVAudioSession.sharedInstance().setActive(true)
try! AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker)
let speech : String = "You have the following items in your To-do list: "
let speechUtterance : AVSpeechUtterance = AVSpeechUtterance(string: speech)
AVSpeechSynthesizer().speakUtterance(speechUtterance)
的代碼工作完全正常,但聲音是從手機的麥克風來了。我想使用揚聲器而不是麥克風。我如何實現這一目標?
是「'try!'」有效的Swift語法? –
我認爲你對覆蓋的理解是背對背的 - 你有沒有試過'.None'而不是'.Speaker'? 。 – Grimxn