Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am creating an application using microsoft inbuilt speech recognition. And i am stuck in the start itself.


Quote:
namespace WpfApplication1
{

public partial class MainWindow : Window
{
private SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
public MainWindow()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new DictationGrammar());
_recognizer.SpeechRecognized += new EventHandler<speechrecognizedeventargs>(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}

void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
foreach (RecognizedWordUnit word in e.Result.Words)
{
listBox1.Items.Add(word.Text);
}
}
}
}


QS : i was wondering in this after i speak a word and it displays in the listbox is there a way to write that recognized word to a text file in " c:\ " ?
Posted

1 solution

martinjam3s wrote:
And i am stuck in the start itself.

If you want to learn speech recognition in C#, read my article:
Speech recognition in C#[^]
martinjam3s wrote:
i was wondering in this after i speak a word and it displays in the listbox is there a way to write that recognized word to a text file in " c:\ " ?

Try this:
C#
foreach (RecognizedWordUnit word in e.Result.Words)
{
      listBox1.Items.Add(word.Text);
      System.IO.File.AppendAllLines(@"C:\file.txt", new string[] { word.Text });
}

Hope this helps.
 
Share this answer
 
v2
Comments
martinjam3s 31-Mar-13 9:16am    
thanks a lot it works!

and what if there was no list box and what ever i spoke went directly to a text file?
Thomas Daniels 31-Mar-13 9:18am    
This works also if you don't have a list box, but if you don't have a list box, you have to remove the line <small>listBox1.Items.Add(word.Text);</small>.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900