Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting first paragraph of wikipedia using Voice C#

Getting first paragraph of wikipedia using Voice C#

Scheduled Pinned Locked Moved C#
helpquestioncsharpphpdatabase
9 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wishingchain
    wrote on last edited by
    #1

    Hi, My name is Wish and I have recently coded an application that recognizes commands I ask it to do(open notepad, gives time, etc.) I now want to be able to ask it a question like "who is Barack Obama" and it will respond with the first paragraph of the wikipedia article. I have this code so far which requires me to manually type in what I want to search for. This is that code

    var webClient = new WebClient();
    var pageSC = webClient.DownloadString("http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&titles=" + textBox1.Text + "&redirects=true");
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(pageSC);

            var fnode = doc.GetElementsByTagName("extract")\[0\];
            try
            {
                string ss = fnode.InnerText;
                Regex regex = new Regex("\\\\<\[^\\\\>\]\*\\\\>");
                string.Format("Before:{0}", ss);
    
                ss = regex.Replace(ss, string.Empty);
                string result = String.Format(ss);
                richTextBox2.Text = result;
            }
            catch
            {
                richTextBox2.Text = "error";
            }
    

    Any and all help will be greatly appreciated. If this is too vauge of a question please tell me and I will try to explain in more detail.

    Thanks, Wish

    P L C 3 Replies Last reply
    0
    • W Wishingchain

      Hi, My name is Wish and I have recently coded an application that recognizes commands I ask it to do(open notepad, gives time, etc.) I now want to be able to ask it a question like "who is Barack Obama" and it will respond with the first paragraph of the wikipedia article. I have this code so far which requires me to manually type in what I want to search for. This is that code

      var webClient = new WebClient();
      var pageSC = webClient.DownloadString("http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&titles=" + textBox1.Text + "&redirects=true");
      XmlDocument doc = new XmlDocument();
      doc.LoadXml(pageSC);

              var fnode = doc.GetElementsByTagName("extract")\[0\];
              try
              {
                  string ss = fnode.InnerText;
                  Regex regex = new Regex("\\\\<\[^\\\\>\]\*\\\\>");
                  string.Format("Before:{0}", ss);
      
                  ss = regex.Replace(ss, string.Empty);
                  string result = String.Format(ss);
                  richTextBox2.Text = result;
              }
              catch
              {
                  richTextBox2.Text = "error";
              }
      

      Any and all help will be greatly appreciated. If this is too vauge of a question please tell me and I will try to explain in more detail.

      Thanks, Wish

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You haven't really said what the problem is that you are facing. I assume that the issue you are having is that you don't know how to do the voice recognition part. Would that be a fair assumption?

      This space for rent

      W 1 Reply Last reply
      0
      • P Pete OHanlon

        You haven't really said what the problem is that you are facing. I assume that the issue you are having is that you don't know how to do the voice recognition part. Would that be a fair assumption?

        This space for rent

        W Offline
        W Offline
        Wishingchain
        wrote on last edited by
        #3

        yeah thats basically it..

        1 Reply Last reply
        0
        • W Wishingchain

          Hi, My name is Wish and I have recently coded an application that recognizes commands I ask it to do(open notepad, gives time, etc.) I now want to be able to ask it a question like "who is Barack Obama" and it will respond with the first paragraph of the wikipedia article. I have this code so far which requires me to manually type in what I want to search for. This is that code

          var webClient = new WebClient();
          var pageSC = webClient.DownloadString("http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&titles=" + textBox1.Text + "&redirects=true");
          XmlDocument doc = new XmlDocument();
          doc.LoadXml(pageSC);

                  var fnode = doc.GetElementsByTagName("extract")\[0\];
                  try
                  {
                      string ss = fnode.InnerText;
                      Regex regex = new Regex("\\\\<\[^\\\\>\]\*\\\\>");
                      string.Format("Before:{0}", ss);
          
                      ss = regex.Replace(ss, string.Empty);
                      string result = String.Format(ss);
                      richTextBox2.Text = result;
                  }
                  catch
                  {
                      richTextBox2.Text = "error";
                  }
          

          Any and all help will be greatly appreciated. If this is too vauge of a question please tell me and I will try to explain in more detail.

          Thanks, Wish

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What are you using for recognizing spoken commands? If it is the MS-agent technology, then it will not accept words that are not defined as a command.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          W 1 Reply Last reply
          0
          • L Lost User

            What are you using for recognizing spoken commands? If it is the MS-agent technology, then it will not accept words that are not defined as a command.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            W Offline
            W Offline
            Wishingchain
            wrote on last edited by
            #5

            I figured out how to use my voice to search for stuff but now I need to get it to Speak the first paragraph...

            L 1 Reply Last reply
            0
            • W Wishingchain

              I figured out how to use my voice to search for stuff but now I need to get it to Speak the first paragraph...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Download the article into a stream, identify the first paragraph and feed that to the TTS engine.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              W 1 Reply Last reply
              0
              • L Lost User

                Download the article into a stream, identify the first paragraph and feed that to the TTS engine.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                W Offline
                W Offline
                Wishingchain
                wrote on last edited by
                #7

                how would I download it to a stream?

                L 1 Reply Last reply
                0
                • W Wishingchain

                  how would I download it to a stream?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  How to: Request Data Using the WebRequest Class | Microsoft Docs[^]

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  1 Reply Last reply
                  0
                  • W Wishingchain

                    Hi, My name is Wish and I have recently coded an application that recognizes commands I ask it to do(open notepad, gives time, etc.) I now want to be able to ask it a question like "who is Barack Obama" and it will respond with the first paragraph of the wikipedia article. I have this code so far which requires me to manually type in what I want to search for. This is that code

                    var webClient = new WebClient();
                    var pageSC = webClient.DownloadString("http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&titles=" + textBox1.Text + "&redirects=true");
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(pageSC);

                            var fnode = doc.GetElementsByTagName("extract")\[0\];
                            try
                            {
                                string ss = fnode.InnerText;
                                Regex regex = new Regex("\\\\<\[^\\\\>\]\*\\\\>");
                                string.Format("Before:{0}", ss);
                    
                                ss = regex.Replace(ss, string.Empty);
                                string result = String.Format(ss);
                                richTextBox2.Text = result;
                            }
                            catch
                            {
                                richTextBox2.Text = "error";
                            }
                    

                    Any and all help will be greatly appreciated. If this is too vauge of a question please tell me and I will try to explain in more detail.

                    Thanks, Wish

                    C Offline
                    C Offline
                    CP_Member888
                    wrote on last edited by
                    #9

                    Instead using `XmlDocument` use AngelSharp library to parse the HTML and extract first paragraph. AngleSharp - Home[^]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups