Note that there are some explanatory texts on larger screens.

plurals
  1. POSpeech Recognition to display pictures from a listbox
    primarykey
    data
    text
    <p>I am having an error with this Speech Recognition, I keep getting "At least one grammar must be loaded before doing a recognition" I can't get the images to display when you say its corresponding linked name.</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using SpeechLib; using System.IO; using System.Speech.Recognition; using System.Globalization; namespace SimpleSpeechRecognition { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private SpeechRecognitionEngine recognizer; private void Form1_Load(object sender, EventArgs e) { speechListBox1.Items.Add("Dog"); speechListBox1.Items.Add("Elephant"); speechListBox1.SpeechEnabled = true; recognizer = new SpeechRecognitionEngine(new CultureInfo("en-GB")); recognizer.SetInputToDefaultAudioDevice(); Choices choices = new Choices("Dog", "Elephant"); GrammarBuilder m_GrammarBuilder = new GrammarBuilder(choices); Grammar m_Speech = new Grammar(m_GrammarBuilder); recognizer.LoadGrammar(m_Speech); recognizer.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(recognizer_SpeechRecognized); recognizer.RecognizeAsync(RecognizeMode.Multiple); } void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { foreach (RecognizedWordUnit word in e.Result.Words) { switch (word.Text) { case "Dog": pictureBox1.Image = Image.FromFile("C:\\" + "dog.jpg");; break; case "Elephant": pictureBox1.Image = Image.FromFile("C:\\" + "elephant.jpg"); break; } } } private void speechListBox1_SelectedIndexChanged(object sender, EventArgs e) { //MessageBox.Show(speechListBox1.SelectedItems[0].ToString()); SayPhrase(speechListBox1.SelectedItems[0].ToString()); //pictureBox1.Image = Image.FromFile("C:\\" + "dog.jpg"); //pictureBox1.Image = Image.FromFile(((FileInfo)speechListBox1.SelectedItem).FullName); pictureBox1.Refresh(); } private void SayPhrase(string PhraseToSay ) { SpeechVoiceSpeakFlags SpFlags = new SpeechVoiceSpeakFlags(); SpVoice Voice = new SpVoice(); Voice.Speak(PhraseToSay, SpFlags); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload