【问题标题】:issue receiving outcomes when sending text to wit.ai向 wit.ai 发送文本时发出接收结果
【发布时间】:2016-04-04 09:45:49
【问题描述】:

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

非常感谢任何帮助!

干杯。

【问题讨论】:

    标签: swift swift2 nsarray nsdictionary wit.ai


    【解决方案1】:

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

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

    并使用 sharedInstance 调用 translateString 函数,即

     Wit.sharedInstance().interpretString(text, customData: nil)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多