Hi, first of all i must thanku all my fellow members for helping me so much in my problems, the help which i never expected this is my first experience with visual studio and because of you all u make it so easy and a fun to learn , i will soon learn more c# and start addressing question here , but till that time i request u to plz co-operate with me as i am still a learner and will always be ,
now i should stop posting a emotional movie script here and ask my doubt so here it is , i am struck on this i have this code:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Speech.Recognition
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create a new SpeechRecognizer instance.
sr = new SpeechRecognizer()
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add("red");
colors.Add("green");
colors.Add("blue");
colors.Add("white");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the actual Grammar instance, and then load it into the speech recognizer.
Grammar g = new Grammar(gb);
sr.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sr.SpeechRecognized += new EventHandler
}
// Simple handler for the SpeechRecognized event.
private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if(e.Result.Text=="Red");
MessageBox.Show(e.Result.Text);
}
private SpeechRecognizer sr;
Now in my application i need to judge numbers 1 to 6 that is when user say number 3 than it should in a string like this ("#3");
Now after this user again speaks something from 500, 1500, 2500 and it advances the previous string to this if he say 1500
("#3 P1500);
This is what i really want , i will add this 1to 6 and 500, 1500, 2500 to my grammar , thats i know but i dont know how after one if detected my system will again look for another work i dont have much knowledge with stirngs also plz help me with that also,
Once again i am a starter so i request you to a give a detail solution.
Thanks in advance
VulpesPosted Jul 26, 2011, 10:13 AM
deepender singlaPosted Jul 27, 2011, 10:37 AM
VulpesPosted Jul 27, 2011, 10:33 AM
deepender singlaPosted Jul 27, 2011, 10:28 AM
in my ext application for a project , i am working in win7 , my phone is connected with bluetooth to my pc , i want i can send particular file to my phone work or pdf any with only one command like system.process.start(xyz) i start that in which i have a written particular address and i am able to send a file when i speak send file , i have done speech part , but the problem i am not able to find any relevant application for these , should i ask in this thread or start a new thread.
deepender singlaPosted Jul 27, 2011, 10:23 AM
VulpesPosted Jul 27, 2011, 10:19 AM
Pleased to hear it's working OK now :)
Incidentally, would you mind trying to reduce the number of 'Accepted Answers' in this and your previous thread (http://www.c-sharpcorner.com/Forums/Thread/132947/how-to-use-value-recieved-in-console-application-in-other-pr.aspx) to just one as we're only supposed to get one per thread.
Usually, when you attempt to mark another post in the same thread as an Accepted Answer, the first Accepted Answer is removed so there must be a bug in the system somewhere.
Many thanks :)
deepender singlaPosted Jul 27, 2011, 5:03 AM
VulpesPosted Jul 26, 2011, 3:33 PM
So, just place it after the previous method:
deepender singlaPosted Jul 26, 2011, 1:12 PM
i made this changes in program:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Speech.Recognition;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string command = "#";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//
// Create a new SpeechRecognizer instance.
sr = new SpeechRecognizer();
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add("red");
colors.Add("green");
colors.Add("blue");
colors.Add("white");
colors.Add("one");
colors.Add("Two");
colors.Add("Three");
colors.Add("Four");
colors.Add("Five");
colors.Add("Six");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// private string command = "#";
// Create the actual Grammar instance, and then load it into the speech recognizer.
Grammar g = new Grammar(gb);
sr.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sr.SpeechRecognized += new EventHandler
// Add this field to form
//private string command = "#";
}
private void processcommand()
{
// Simple handler for the SpeechRecognized event.
private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{// Add this field to form
//private string command = "#";
if (command == "#")
{
switch (e.Result.Text)
{
case "one":
command += "1 P";
MessageBox.Show(command);
return;
case "Two":
command += "2 P";
MessageBox.Show(command);
return;
case "Three":
command += "3 P";
MessageBox.Show(command);
return;
case "Four":
command += "4 P";
MessageBox.Show(command);
return;
case "Five":
command += "5 P";
MessageBox.Show(command);
return;
case "Six":
command += "6 P";
MessageBox.Show(command);
return;
default:
MessageBox.Show("Please speak a number between one and six");
return;
}
}
else if (command.Length == 4)
{
switch (e.Result.Text)
{
case "red":
command += "500";
MessageBox.Show(command);
break;
case "blue":
command += "1500";
MessageBox.Show(command);
break;
case "green":
command += "2500";
MessageBox.Show(command);
break;
default:
MessageBox.Show("Please speak one of these numbers: 500, 1500 or 2500");
return;
}
processcommand(); // need to add this method
command = "#"; // reset command
MessageBox.Show("Please wait until previous command is processed");
command = "#";
}
//else if (e.Result.Text == "red");
// MessageBox.Show(e.Result.Text);
}
private SpeechRecognizer sr;}}}
i got error like:
Error2Type or namespace definition, or end-of-file expectedE:\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs14439WindowsFormsApplication1
Error1} expectedE:\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs7310WindowsFormsApplication1
may be i have created a mess in a program i am not able to judge where do i need to add this function processcommand and what shoukd i need to add and were i call this function , plz help i ahve tries a lot but not able to judge basically i am quite new with c#. sir plz help
VulpesPosted Jul 26, 2011, 12:20 PM
However, these look like the commands you were using in your SerialPort program so I imagine that you'll need to add code to write them to the port.
deepender singlaPosted Jul 26, 2011, 12:09 PM
VulpesPosted Jul 26, 2011, 11:52 AM
I'd try changing the code I suggested earlier to the following:
deepender singlaPosted Jul 26, 2011, 11:40 AM
VulpesPosted Jul 26, 2011, 11:33 AM
deepender singlaPosted Jul 26, 2011, 10:59 AM
deepender singlaPosted Jul 26, 2011, 10:48 AM
VulpesPosted Jul 26, 2011, 10:42 AM
deepender singlaPosted Jul 26, 2011, 10:36 AM
// Add this field to form
in my code i try adding at many places but it is showing error like plz tell me exact place wherei need to add . the
errors are when i add it private form load1