Whenever I try to encode any speech recognition program on my laptop, I always get the same messages as mentioned below. I can always compile my code and get a windows application. But the problem is that the program will not detect my voice. And the program will not work.
I am very sure that my codes work fine, as I usually take codes from youtube videos, for example: https://www.youtube.com/watch?v=KR0-UYUGYgA and many others. I use the .NET framework 4 client profile for my projects .. I only refer to "system.speech" ... What could be my problem?
The debug messages I receive are:
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 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) {
Thale
source share