从语音识别器中调用按钮对象 [英] Calling button object from Speech Recognizer

查看:83
本文介绍了从语音识别器中调用按钮对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Vista中的WPF应用程序处理语音识别项目.我想先调用语音识别引擎,然后再调用我的应用程序窗口.但是正好相反.首先,我的应用程序窗口运行&然后在单击按钮后,语音引擎启动.以下是我尝试作为演示的代码.

I am working over a Speech Recognition project using WPF application in Windows Vista. I want to call the Speech recognition engine and then my application window. But exactly opposite is going on. First my application window runs & then after clicking a button the speech engine starts. Following is the code that I have tried as a demo.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Speech;
using System.Speech.Recognition; 
namespace WpfApplication1
{
// protected SpeechRecognizer spRecognizer;
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(((Button)sender).ToString());
SpeechRecognizer spRecognizer = new SpeechRecognizer();
spRecognizer.Enabled=true;
spRecognizer.SpeechRecognized+=new EventHandler<SpeechRecognizedEventArgs>(spRecognizer_SpeechRecognized);
} 
void spRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
throw new NotImplementedException();
string str=e.Result.Text;
MessageBox.Show(str);
}
}
}

请提出一些建议.

推荐答案

使用某种方法(例如SetupSpeech)设置语音识别器.从主窗口的构造函数中调用此方法.

或者,重写System.Windows.Window.OnContentRendered并从此方法调用SetupSpeech.

—SA
Setup your speech recognizer in some method, say SetupSpeech. Call this method from the constructor of your main window.

Alternatively, override System.Windows.Window.OnContentRendered and call SetupSpeech from this method.

—SA


这篇关于从语音识别器中调用按钮对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆