Ios 使用语音对文本获取文本时,文本对语音不起作用

Ios 使用语音对文本获取文本时,文本对语音不起作用,ios,swift,avspeechsynthesizer,Ios,Swift,Avspeechsynthesizer,对于语音到文本-我使用了“语音框架”,并使用它创建了演示。 但是在得到一个文本后,我想说文本字段文本 var synth = AVSpeechSynthesizer() var myUtterance = AVSpeechUtterance(string: textfield.text) myUtterance.rate = 0.3 synth.speak(myUtterance) 但是上面的代码不起作用。 在这里,我附加了演示项目链接:您的代码正在工作,但您听不到声音,因为当您开始录制时,您

对于语音到文本-我使用了“语音框架”,并使用它创建了演示。 但是在得到一个文本后,我想说文本字段文本

var synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance(string: textfield.text)
myUtterance.rate = 0.3
synth.speak(myUtterance)
但是上面的代码不起作用。
在这里,我附加了演示项目链接:

您的代码正在工作,但您听不到声音,因为当您开始录制时,您将音频会话的类别设置为“AVAudioSessionCategoryRecord”。此类别用于录制音频并使播放音频静音。然后您必须更改此设置才能听到任何声音。 试试这个:

let audioSession = AVAudioSession.sharedInstance()  //2
    do {
        try audioSession.setCategory(AVAudioSessionCategorySoloAmbient)
        try audioSession.setMode(AVAudioSessionModeSpokenAudio)
        try audioSession.setActive(true, with: .notifyOthersOnDeactivation)
    } catch {
        print("audioSession properties weren't set because of an error.")
    }


    myUtterance = AVSpeechUtterance(string: textView.text!)
    myUtterance.rate = 0.3
    synth.speak(myUtterance)

使用的语言是什么?是否确实连接到internet()?是的,我的internet已连接。@AhmadF我创建了文本到语音和语音到文本的演示。两种功能都有。