我使用以下方法通过按钮按下函数向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的文档
任何帮助都是非常感谢的!
干杯。
发布于 2016-06-14 14:19:58
Wit为用户提供了一个sharedInstance (单例),因此您可以像-一样启动它:
Wit.sharedInstance().accessToken = "TOKEN"
Wit.sharedInstance().delegate = self并使用interpretString调用sharedInstance函数,即
Wit.sharedInstance().interpretString(text, customData: nil)https://stackoverflow.com/questions/36399273
复制相似问题