我使用下面的代码添加文本到语音功能在我的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