Getting first paragraph of wikipedia using Voice C#
-
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
-
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
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
-
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
yeah thats basically it..
-
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
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.
-
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.
I figured out how to use my voice to search for stuff but now I need to get it to Speak the first paragraph...
-
I figured out how to use my voice to search for stuff but now I need to get it to Speak the first paragraph...
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.
-
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.
how would I download it to a stream?
-
how would I download it to a stream?
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.
-
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
Instead using `XmlDocument` use AngelSharp library to parse the HTML and extract first paragraph. AngleSharp - Home[^]