Exemple #1
0
        //void _rg_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        void _rg_SpeechRecognized(Object sender, RecognitionEventArgs e)
        {
            var conf = e.Confidence;

            if (conf < 0.5)
            {
                return;
            }

            var txt = e.Text;

            // 语音识别前,必须先识别前缀名称,然后几秒内识别关键字
            if (_Tip.AddSeconds(3) < DateTime.Now)
            {
                // 此时只识别前缀
                if (txt != Name)
                {
                    return;
                }

                XTrace.WriteLine("语音识别:{0} {1}", txt, conf);

                // 现在可以开始识别关键字啦
                _Tip = DateTime.Now;
            }
            else
            {
                XTrace.WriteLine("语音识别:{0} {1}", txt, conf);

                if (_dic.TryGetValue(txt, out var func))
                {
                    func();
                }
            }
        }
Exemple #2
0
        void _rg_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result == null)
            {
                return;
            }

            var ev = new RecognitionEventArgs(e.Result.Confidence, e.Result.Text);

            SpeechRecognized?.Invoke(sender, ev);
        }