Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                SpeechFactory speechFactory = SpeechFactory.FromSubscription(luisKey, "");
                recognizer = speechFactory.CreateIntentRecognizer("zh-cn");

                // 创建意图识别器用到的模型
                var model = LanguageUnderstandingModel.FromSubscription(luisKey, luisAppId, luisRegion);

                // 将模型中的意图加入到意图识别器中
                recognizer.AddIntent("None", model, "None");
                recognizer.AddIntent("TurnOn", model, "TurnOn");
                recognizer.AddIntent("TurnOff", model, "TurnOff");

                // 挂载识别中的事件
                // 收到中间结果
                recognizer.IntermediateResultReceived += Recognizer_IntermediateResultReceived;
                // 收到最终结果
                recognizer.FinalResultReceived += Recognizer_FinalResultReceived;
                // 发生错误
                recognizer.RecognitionErrorRaised += Recognizer_RecognitionErrorRaised;

                // 启动语音识别器,开始持续监听音频输入
                recognizer.StartContinuousRecognitionAsync();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }