获取HTML标头的内容

时间:2013-12-20 17:33:08

标签: c# web voice-recognition

我正在努力让Windows 7上的语音识别软件转到http://www.oxforddictionaries.com/并获取一个定义,如果任何单词存在,我可能会给识别器。

我现在的做法相当基础,很可能是由于我对语音识别经验不足。我从微软的页面中获取了示例代码,并尝试修改sre_SpeechRecognized()方法。

我被困了,因为我不知道如何真正阅读他们的HTML内容并在RichTextBox中显示它。通过使用谷歌浏览器阅读元素,我得到了以下信息(这个例子是关于头发的定义):

<div id="entryPageContent">
    <div>
        <section class="senseGroup">
            <h3 class="partOfSpeech">
                <span class="partOFSpeech">noun</span> <-- So it can be a noun
            </h3>
            <ul class="sense-entry">
                <li class="sense sense-type-core scrollerBlock">
                    <div class="senseInnerWrapper">
                    <a name="hair__2"> </a>
                    <span class="iteration">1</span> <-- First definition
                    <span class="definition">
                    "any of the fine thread-like strands growing from the skin of humans, mammals, and some other animals:" <--- The definition itself
                    </span>
                    <span class="exampleGroup exGrBreak">
                        <em class="example">coarse outer hairs overlie the thick underfur</em> <--- An Example

代码从那里开始。一个单词可以有多个类(如名词,形容词,动词等),一个单词可以有多个定义,一个单词可以有多个定义。

我看到的代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Speech.Recognition;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VoiceBotForm
{
    public partial class Form1 : Form
    {
        public SpeechRecognizer recognizer;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Create new SpeechRecogniitionEngine instance.
            recognizer = new SpeechRecognizer();

            // Create a simple grammar that recognizes words.
            Choices words = new Choices();
            words.Add(new string[] {"define"});

            // Create a GrammarBuilder object and append the Choices object
            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(words);

            // Create the Grammar instance and load it into the speech recognition engine.
            Grammar g = new Grammar(gb);
            recognizer.LoadGrammar(g);

            // Register a handler for the SpeechRecognized event.
            recognizer.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
        }

        void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if(e.Result.Text.Contains("define"))
            {
                String result = e.Result.Text.Replace("define", "");
                result.Trim();
                WebRequest request = WebRequest.Create("http://www.oxforddictionaries.com/definition/english/" + result + "?q=" + result);
                WebResponse response = request.GetResponse();
                //What do I do now??
            }
        }
    }
}

正如你在代码注释中看到的那样,我被困在那一点上,因为我不知道在得到初始响应之后如何继续这个。当我得到所有数据时,我想把它放在RichTextBox中。

0 个答案:

没有答案