Whenever I attempt to code any speech recognition program in my laptop,I always get the same messages as mentioned below..I can always compile my code and get the windows form application working..But the problem is, the program will not detect my voice..And the program wont work..
I am very sure my codes works fine as I usually take the codes from youtube videos like : https://www.youtube.com/watch?v=KR0-UYUGYgA and many more.. I am using .NET framework 4 client profile for my projects.. I make reference only to "system.speech"...What might be my problem ?
Debug messages that I get :
speaker.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
Sample code that I tried :
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.Synthesis;
using System.Speech.Recognition;
using System.Threading;
using System.Threading.Tasks;
namespace speaker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SpeechSynthesizer sSynth = new SpeechSynthesizer();
PromptBuilder pBuilder = new PromptBuilder();
SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
pBuilder.ClearContent();
pBuilder.AppendText(textBox1.Text);
sSynth.Speak(pBuilder);
}
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
button2.Enabled = true;
Choices sList = new Choices();
sList.Add(new string[]{"hello","test","it works","how","are","you","today"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
try
{
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sRecognize_SpeechRecognized);
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return;
}
}
void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//if (e.Result.Confidence >= 0.3)
MessageBox.Show("speech is:" + e.Result.Text.ToString());
}
}
}