Search code examples
azure-cognitive-services

Can't get Speech SDK to return LUIS intents in swift


Started with the basic helloworld example this recognises speech correctly however I want to get intents back so modified the ViewController.swift as follows:

    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")
        }
    }

The output is

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

There is long pause (30+ seconds) before the "recognition result" message is output. Looking on LUIS I can see that no utterances have been sent to endpoint. The LUIS subscription, appId I have used extensively for bots from C# and JS so reasonably confident that these are correct (I haven't included here for obvious reasons).

Hopefully something simple I have missed - any help greatly appreciated


Solution

  • Solution turned out to be related to setting up new paid for subscription and assigning that to LUIS model as resource.