Ref: https://www.wpf-tutorial.com/audio-video/speech-recognition-making-wpf-listen/
Kinect SDK 1.8 SpeechBasic-WPF
1-1. ASUS X450J @ Windows 10 x64 Edu
1-2. Kinect SDK 1.8
1-3. Visual Studio 2017
2 Ex from https://www.wpf-tutorial.com/audio-video/speech-recognition-making-wpf-listen/
2-1 New WPF Project
2-2 Add System.Speech.DLL
2-3 using System.Speech.Recognition;
2-4
SpeechRecognitionEngine speechRecognizer = new SpeechRecognitionEngine();
public MainWindow()
{
InitializeComponent();
speechRecognizer.SpeechRecognized += SpeechRecognizer_SpeechRecognized;
GrammarBuilder grammarBuilder = new GrammarBuilder();
Choices commandChoices = new Choices("weight", "color", "size", "顏色");
grammarBuilder.Append(commandChoices);
Choices valueChoices = new Choices();
valueChoices.Add("normal", "bold");
valueChoices.Add("red", "green", "blue");
valueChoices.Add("small", "medium", "large");
valueChoices.Add("紅色", "黑色", "白色");
grammarBuilder.Append(valueChoices);
speechRecognizer.LoadGrammar(new Grammar(grammarBuilder));
speechRecognizer.SetInputToDefaultAudioDevice();
speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
}
private void SpeechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
this.Content = e.Result.Text;
//string command = e.Result.Words[0].Text.ToLower();
//string value = e.Result.Words[1].Text.ToLower();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
speechRecognizer.RecognizeAsyncStop();
speechRecognizer.Dispose();
}
3. Ref : SpeechBasic-WPF and ex2 Notes: The default CultureInfo is zh-TW
@ Microsoft.Speech ==> without zh-TW.
3-1 Add Ref
C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Speech\11.0.0.0__31bf3856ad364e35\Microsoft.Speech.dll
3-2 using Microsoft.Speech.Recognition;
3-3
public partial class MainWindow : Window
{
SpeechRecognitionEngine speechRecognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
public MainWindow()
{
InitializeComponent();
speechRecognizer.SpeechRecognized += SpeechRecognizer_SpeechRecognized;
GrammarBuilder grammarBuilder = new GrammarBuilder();
grammarBuilder.Culture = new System.Globalization.CultureInfo("en-US");
// System.Threading.Thread.CurrentThread.CurrentCulture;
Choices commandChoices = new Choices("weight", "color", "size");
grammarBuilder.Append(commandChoices);
Choices valueChoices = new Choices();
valueChoices.Add("normal", "bold");
valueChoices.Add("red", "green", "blue");
valueChoices.Add("small", "medium", "large");
//valueChoices.Add("紅色", "黑色", "白色");
grammarBuilder.Append(valueChoices);
speechRecognizer.LoadGrammar(new Grammar(grammarBuilder));
speechRecognizer.SetInputToDefaultAudioDevice();
speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
}
private void SpeechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
this.Content = e.Result.Text;
string command = e.Result.Words[0].Text.ToLower();
string value = e.Result.Words[1].Text.ToLower();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
speechRecognizer.RecognizeAsyncStop();
speechRecognizer.Dispose();
}
沒有留言:
張貼留言