首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向wit.ai发送文本时发出接收结果

向wit.ai发送文本时发出接收结果
EN

Stack Overflow用户
提问于 2016-04-04 09:45:49
回答 1查看 198关注 0票数 0

我使用以下方法通过按钮按下函数向wit.ai发送文本:

代码语言:javascript
复制
@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函数来强制它在按下按钮时运行,但是我无法计算出在“结果”参数中应该使用什么。有人能帮上忙吗?我不确定在按下按钮后是否有不同的方法来运行这个函数?这是一项功能:

代码语言:javascript
复制
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的文档

任何帮助都是非常感谢的!

干杯。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-14 14:19:58

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

代码语言:javascript
复制
Wit.sharedInstance().accessToken = "TOKEN"
Wit.sharedInstance().delegate = self

并使用interpretString调用sharedInstance函数,即

代码语言:javascript
复制
 Wit.sharedInstance().interpretString(text, customData: nil)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36399273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档