【问题标题】:Use Kinect Voice Recognition to run Metro GUI application使用 Kinect 语音识别运行 Metro GUI 应用程序
【发布时间】:2012-07-02 23:03:13
【问题描述】:

我想使用 kinect sdk 语音识别从 Metro UI 运行应用程序。 例如,当我说:News 这个词时,它会从 Metro UI 运行 News 的应用程序。

谢谢大家!

问候!

【问题讨论】:

    标签: c# microsoft-metro kinect


    【解决方案1】:

    首先您需要与音频流建立连接并开始收听:

        private KinectAudioSource source;
        private SpeechRecognitionEngine sre;
        private Stream stream;
    
    private void CaptureAudio()
            {
    
                this.source = KinectSensor.KinectSensors[0].AudioSource;
                this.source.AutomaticGainControlEnabled = false;
                this.source.EchoCancellationMode = EchoCancellationMode.CancellationOnly;
                this.source.BeamAngleMode = BeamAngleMode.Adaptive;
    
            RecognizerInfo info = SpeechRecognitionEngine.InstalledRecognizers()
                .Where(r => r.Culture.TwoLetterISOLanguageName.Equals("en"))
                .FirstOrDefault();
    
            if (info == null) { return; }
            this.sre = new SpeechRecognitionEngine(info.Id);
    
            if(!isInitialized) CreateDefaultGrammars();
    
            sre.LoadGrammar(CreateGrammars()); //Important step
    
            this.sre.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>
                    (sre_SpeechRecognized);
            this.sre.SpeechHypothesized +=
                new EventHandler<SpeechHypothesizedEventArgs>
                    (sre_SpeechHypothesized);
            this.stream = this.source.Start();
            this.sre.SetInputToAudioStream(this.stream, new SpeechAudioFormatInfo(
                EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            this.sre.RecognizeAsync(RecognizeMode.Multiple);
    
        }
    

    首先,您可以在示例中看到一个重要的步骤sre.LoadGrammar(CreateGrammars()); 创建并加载语法,因此您必须创建方法CreateGrammars()

    private Grammar CreateGrammars()
            {
    
            var KLgb = new GrammarBuilder();
            KLgb.Culture = sre.RecognizerInfo.Culture;
            KLgb.Append("News");
            return Grammar(KLgb);
    
        }
    

    上面的示例为“新闻”这个词创建了一个语法监听。一旦被识别(在您的语法中所说的单词的概率高于阈值),语音识别器引擎 (sre) 就会引发 SpeechRecognized 事件。

    当然,您需要为这两个事件(Hypothetize、Recognize)添加正确的处理程序:

        private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
    
            this.RecognizedWord = e.Result.Text;
            if (e.Result.Confidence > 0.65) InterpretCommand(e);
        }
    

    知道您所要做的就是编写 InterpretCommand 方法,它可以做任何您想做的事情(如运行 Metro 应用程序;))。如果字典中有多个单词,则该方法必须解析识别的文本并验证这是被识别的单词 news。

    Here你可以下载一本关于 Kinect 的好书的样本:Beginning Kinect Programming with the Microsoft Kinect SDK(不幸的是这本书本身不是免费的)。在 Chapter7\PutThatThereComplete\ 文件夹中,您有一个使用音频的示例,您可以从中获得灵感。

    【讨论】:

    • 完美....我按照你的代码 sn-p...我已经运行了代码,它的功能正常...现在我面前有地铁 GUI,但是当我说话时“新闻”它什么也没运行...我想模拟点击图标新闻...如何做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多