我使用以下方法通过按钮按下功能向 wit.ai 发送文本:
@IBAction func searchButton(sender: AnyObject) {
searchQueryText = searchTextInput.text!
if searchQueryText != "" {
wit.interpretString(searchQueryText, customData: nil)
}
func interpretString(string: String, customData: AnyObject) {
}
当文本发送到 wit.ai 时,效果很好。然而,我没有收到 wit.ai 对应用程序的回复。如果使用麦克风,我可以获得很好的响应,但不能得到文本。我尝试调用 witDidGraspIntent 函数来强制它在按下按钮时运行,但我无法弄清楚应该在“结果”参数中使用什么。有人可以帮忙吗?我不确定按下按钮后是否有不同的方式来运行该功能?这是函数:
func witDidGraspIntent(outcomes: [AnyObject]!, messageId: String!, customData: AnyObject!, error e: NSError!) {
if ((e) != nil) {
print("\(e.localizedDescription)")
return
}
let outcomes : NSArray = outcomes!
let firstOutcome : NSDictionary = outcomes.objectAtIndex(0) as! NSDictionary
if let intent = firstOutcome.objectForKey("intent") as? String {
searchResultsIntent = intent
}
if searchResultsIntent == "searchIntent" {
intentLabel.text = "\(searchResultsIntent)"
print(outcomes[0])
} else {
intentLabel.text = "I'm sorry, I did not understand that."
}
}
这里是 wit.ai 的文档:https://wit.ai/docs/ios/4.0.0/api
非常感谢任何帮助!
干杯。
最佳答案
Wit sdk 提供了一个共享实例(单例)供用户使用,因此您可以像这样启动它:
Wit.sharedInstance().accessToken = "TOKEN"
Wit.sharedInstance().delegate = self
并使用sharedInstance调用interpretString函数,即
Wit.sharedInstance().interpretString(text, customData: nil)
关于swift - 向 wit.ai 发送文本时接收结果的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36399273/