无法获取Speech SDK迅速返回LUIS意图

时间:2019-12-16 08:04:42

标签: microsoft-cognitive

从基本的helloworld example开始,它可以正确识别语音,但是我想找回意图,因此对ViewController.swift进行了如下修改:

    func recognizeFromMic() {
        var speechConfig: SPXSpeechConfiguration?

        do {
            try speechConfig = SPXSpeechConfiguration(subscription: sub, region: region)
        } catch {
            print("error \(error) happened")
            speechConfig = nil
        }

        speechConfig?.speechRecognitionLanguage = "en-US"
        let audioConfig = SPXAudioConfiguration()

        let languageUnderstandingModel = SPXLanguageUnderstandingModel(subscription: luisSub, withAppId: luisAppId, andRegion: luisRegion)

        let reco = try! SPXIntentRecognizer(speechConfiguration: speechConfig!, audioConfiguration: audioConfig)
        reco.addAllIntents(from: languageUnderstandingModel!)

        reco.addRecognizingEventHandler() {reco, evt in
            print("intermediate recognition result: \(evt.result?.text ?? "(no result)")")
            self.logResultReason(reason: (evt.result?.reason)!);

            self.updateLabel(text: evt.result?.text, color: .gray)
        }

        updateLabel(text: "Listening ...", color: .gray)
        print("Listening...")

        let result = try! reco.recognizeOnce()
        print("recognition result: \(result.text ?? "(no result)")")
        self.logResultReason(reason: result.reason);

        updateLabel(text: result.text, color: .black)
    }

    func logResultReason(reason: SPXResultReason) {
        switch reason {
        case .canceled:
            print("cancelled")
            break
        case .noMatch:
            print("no Match")
            break
        case .recognizedIntent:
            print("Intent")
            break
        case .recognizingIntent:
            print("Recognizing Intent")
            break
        case .recognizingSpeech:
            print("Recognizing Speech")
            break
        case .recognizedSpeech:
            print("Speech")
            break
        default:
            print("Other")
        }
    }

输出为

Token: 
Listening...
2019-12-16 20:43:57.974675+1300 helloworld[51677:4869822] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000024d32c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2019-12-16 20:43:58.156465+1300 helloworld[51677:4869886]  PropertyID=1667788144 is NULL
intermediate recognition result: how
Recognizing Speech
intermediate recognition result: hello
Recognizing Speech
intermediate recognition result: hello world
Recognizing Speech
recognition result: 
cancelled

在输出“识别结果”消息之前,需要长时间的停顿(超过30秒)。通过查看LUIS,我可以看到没有话语发送到端点。 LUIS订阅,我已广泛用于C#和JS的机器人的appId appId,因此相当有把握地确信它们是正确的(出于明显的原因,此处未包括在内)。

希望我错过了一些简单的事情-非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

事实证明,解决方案与设置新的付费订阅并将其作为资源分配给LUIS模型有关。