0

我正在使用以下内容通过按钮按下功能向 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

非常感谢任何帮助!

干杯。

4

1 回答 1

0

Wit sdk 为用户提供了一个 sharedInstance (单例)供用户使用,因此您可以像这样启动它:

Wit.sharedInstance().accessToken = "TOKEN"
Wit.sharedInstance().delegate = self

并使用 sharedInstance 调用 translateString 函数,即

 Wit.sharedInstance().interpretString(text, customData: nil)
于 2016-06-14T14:19:58.607 回答