Click here to Skip to main content
15,887,962 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to count number of word in text Pin
Robin Panther30-Apr-06 10:27
Robin Panther30-Apr-06 10:27 
GeneralRe: How to count number of word in text Pin
eyalso30-Apr-06 10:46
eyalso30-Apr-06 10:46 
GeneralRe: How to count number of word in text Pin
Graham Nimbley30-Apr-06 11:35
Graham Nimbley30-Apr-06 11:35 
Questionxml + xslt = html ? Pin
Khepry30-Apr-06 5:47
Khepry30-Apr-06 5:47 
AnswerRe: xml + xslt = html ? Pin
Ravi Bhavnani30-Apr-06 7:41
professionalRavi Bhavnani30-Apr-06 7:41 
QuestionC# ODBC Pin
XeoN-Kc30-Apr-06 4:19
XeoN-Kc30-Apr-06 4:19 
AnswerRe: C# ODBC Pin
Ravi Bhavnani30-Apr-06 7:43
professionalRavi Bhavnani30-Apr-06 7:43 
QuestionSpeech programming Pin
TheEagle30-Apr-06 2:27
TheEagle30-Apr-06 2:27 
Hi..
Ihave downloaded the microsoft SAPI SDK to make a simple speech Recognition C# application.After search the internet for examples i wrote the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using SpeechLib;
using System.IO;
namespace ReviewWinApp
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{private SpSharedRecoContext objRecoContext;
private SpeechLib.ISpeechRecoGrammar grammar;

private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox tbxOFile;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton rdoEVoice;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Button button2;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();


//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.button1 = new System.Windows.Forms.Button();
this.tbxOFile = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.rdoEVoice = new System.Windows.Forms.RadioButton();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
this.objRecoContext = new SpSharedRecoContext();
this.objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "&File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.menuItem2.Text = "Open";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.menuItem3.Text = "New";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Shortcut = System.Windows.Forms.Shortcut.CtrlE;
this.menuItem4.Text = "Exit";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 184);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Read Text";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tbxOFile
//
this.tbxOFile.Location = new System.Drawing.Point(32, 16);
this.tbxOFile.Multiline = true;
this.tbxOFile.Name = "tbxOFile";
this.tbxOFile.Size = new System.Drawing.Size(384, 160);
this.tbxOFile.TabIndex = 1;
this.tbxOFile.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.rdoEVoice);
this.groupBox1.Location = new System.Drawing.Point(168, 224);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(280, 40);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Voice Orders";
//
// rdoEVoice
//
this.rdoEVoice.Location = new System.Drawing.Point(3, 16);
this.rdoEVoice.Name = "rdoEVoice";
this.rdoEVoice.Size = new System.Drawing.Size(133, 24);
this.rdoEVoice.TabIndex = 0;
this.rdoEVoice.Text = "Enable Voice Orders";
this.rdoEVoice.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(104, 184);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "TestRecognition";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.tbxOFile);
this.Controls.Add(this.button1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FilesReader";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
SpeechLib.SpVoiceClass sp=new SpVoiceClass();
sp.Speak(tbxOFile.Text,SpeechVoiceSpeakFlags.SVSFDefault);
}

private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{//SpSharedRecoContext objRecoContext;
if(rdoEVoice.Checked==true)
{


grammar = objRecoContext.CreateGrammar(0);
grammar.DictationLoad("", SpeechLoadOption.SLOStatic);

/*grammar=objRecoContext.CreateGrammar(1);
grammar.CmdLoadFromFile("D:\\newDocuments\\FrequentlyUse\\listg.xml",SpeechLoadOption.SLODynamic);
grammar.CmdSetRuleIdState(0,SpeechRuleState.SGDSActive);*/


}
else
{
grammar.DictationSetState(SpeechRuleState.SGDSInactive);
this.objRecoContext.State=SpeechRecoContextState.SRCS_Disabled;
}
}
public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
string strData = Result.PhraseInfo.GetText(0, -1, true) ;
// Debug.WriteLine("Recognition: " + strData + ", " + StreamNumber + ", " + StreamPosition);
tbxOFile.Text+= strData;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
StreamReader rd;
string fName;
OpenFileDialog of=new OpenFileDialog();
of.Filter="txt files (*.txt)|*.txt|All Files (*.*)|*.*";
of.FilterIndex=2;
of.InitialDirectory="C:\\";
if(of.ShowDialog()==DialogResult.OK)
{
fName=of.FileName;
rd=new StreamReader(fName);
while(rd.Peek()!=-1)
{
tbxOFile.Text+=rd.ReadLine();
}
rd.Close();
}
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{

}

private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void Form1_Load(object sender, System.EventArgs e)
{
}

private void button2_Click(object sender, System.EventArgs e)
{
this.objRecoContext = new SpSharedRecoContext();
this.objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
this.objRecoContext.State=SpeechRecoContextState.SRCS_Enabled;
grammar = objRecoContext.CreateGrammar(0);
grammar.CmdLoadFromFile("D:\\newDocuments\\FrequentlyUse\\tryRecog.xml",SpeechLoadOption.SLODynamic);
}
}
}

But unfortunately nothing happend.Could any one help?
AnswerRe: Speech programming Pin
kasik30-Apr-06 10:47
kasik30-Apr-06 10:47 
GeneralRe: Speech programming Pin
TheEagle30-Apr-06 21:24
TheEagle30-Apr-06 21:24 
QuestionRe: Speech programming Pin
TheEagle6-May-06 3:58
TheEagle6-May-06 3:58 
AnswerRe: Speech programming Pin
kasik6-May-06 13:15
kasik6-May-06 13:15 
GeneralRe: Speech programming Pin
TheEagle6-May-06 16:44
TheEagle6-May-06 16:44 
QuestionCreate a thread-safe timer? Pin
Erikerikerikerikerassa30-Apr-06 2:08
Erikerikerikerikerassa30-Apr-06 2:08 
AnswerRe: Create a thread-safe timer? Pin
Ravi Bhavnani30-Apr-06 3:05
professionalRavi Bhavnani30-Apr-06 3:05 
GeneralRe: Create a thread-safe timer? Pin
Erikerikerikerikerassa30-Apr-06 3:43
Erikerikerikerikerassa30-Apr-06 3:43 
GeneralRe: Create a thread-safe timer? Pin
Ravi Bhavnani30-Apr-06 3:53
professionalRavi Bhavnani30-Apr-06 3:53 
GeneralRe: Create a thread-safe timer? Pin
leppie30-Apr-06 7:20
leppie30-Apr-06 7:20 
GeneralRe: Create a thread-safe timer? Pin
Ravi Bhavnani30-Apr-06 7:37
professionalRavi Bhavnani30-Apr-06 7:37 
Questionneed help to pain a picture Pin
f_o_x30-Apr-06 2:02
f_o_x30-Apr-06 2:02 
AnswerRe: need help to pain a picture Pin
CWIZO30-Apr-06 4:15
CWIZO30-Apr-06 4:15 
AnswerRe: need help to pain a picture Pin
Guffa30-Apr-06 5:50
Guffa30-Apr-06 5:50 
Questionvedio files Pin
walaa ibraheem30-Apr-06 0:56
walaa ibraheem30-Apr-06 0:56 
Questionaccessing shared folder in windows application Pin
WCup29-Apr-06 22:15
WCup29-Apr-06 22:15 
AnswerRe: accessing shared folder in windows application Pin
Ravi Bhavnani30-Apr-06 0:52
professionalRavi Bhavnani30-Apr-06 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.