Following is the code to recognize numbers and strings, and having different behavior depending on operating system.
For running project you need to Add Reference of System.Speech.Recognition by Click on Project then click on Add References and find System.Speech.Recognition
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
namespace NumbeRecognitionTest
{
public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}
void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
lblReuslt.Text = e.Result.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
//recoTest1();
recoTest2();
}
//Recognition of following choices only work with Vista but doesn't work with XP with Speech SDK5.2
public void recoTest1()
{
var c = new Choices();
for (var i = 0; i <= 100; i++)
c.Add(i.ToString());
c.Add("go");
c.Add("delete record");
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
//Recognition of following choices Work with vista & XP with Speech SDK5.2
public void recoTest2()
{
var c = new Choices();
c.Add("one");
c.Add("two");
c.Add("three");
c.Add("four");
c.Add("five");
c.Add("twenty five");
c.Add("fifty six");
c.Add("go");
c.Add("delete record");
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
}
}
Please do let me know any updates.
I have found the number recognition doesn't work for SDK5.2 and function recoTest1 doesn't work on it.
No comments:
Post a Comment