我正试图在我的swift应用程序中访问API.AI出现的textresponse。但是.speech属性被低估了,我已经合法地尝试了最后40分钟的一切。有人可以告诉我怎么样?以下是我的代码:
@IBAction func sendMessage(_ sender: Any) {
let request = ApiAI.shared().textRequest()
if let text = self.messageField.text, text != "" {
request?.query = text
} else {
return
}
request?.setMappedCompletionBlockSuccess({ (request, response) in
let response = response as! AIResponse
if let textResponse = response.result.fulfillment.speech {
self.speechAndText(text: textResponse)
}
}, failure: { (request, error) in
print(error!)
})
ApiAI.shared().enqueue(request)
messageField.text = ""
}
提前致谢。
答案 0 :(得分:0)
在其他地方找到,以防有人需要回答同一问题:
let response = response as! AIResponse
if let msgs = response.result.fulfillment.messages {
let resp = msgs [ 0 ] as NSDictionary
print(resp.value(forKey: "speech") as! String)
}