using System;
using System.Windows;
using System.Speech.Recognition;

namespace Speech_Recognition
{
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();

            SpeechRecognizer recognizer = new SpeechRecognizer();
            GrammarBuilder builder = new GrammarBuilder();
            builder.Append(new Choices("二", "三", "四", "五", "六", "七",
              "八", "九", "十", "十一", "十二", "十三", "十四"));
            builder.Append("的", 0, 1);
            builder.Append(new Choices("哈", "师大", "斯蒂芬", "斯蒂"));
            recognizer.LoadGrammar(new Grammar(builder));

            recognizer.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
        }

        void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            MessageBox.Show("你说: " + e.Result.Text);
        }
    }
}

posted on 2009-09-09 13:17  Yincheng  阅读(426)  评论(0编辑  收藏  举报