Gdy mówię "Print my name" program mówi swoją kwestie (syntezatorem mowy) i po tym od razu przechodzi do default'owego swich'a (kompletnie pomija oba case'y)
if (speech == "Print my name")
{
Jan.SpeakAsync("Who do I have the pleasure of talking to?");
switch (e.Result.Text)
{
case "Wall":
richTextBox1.Text += "\nSebastian";
break;
case "Table":
richTextBox1.Text += "\nAleksandra";
break;
default:
MessageBox.Show("ERROR!"); break;
}
}
moje pytanie brzmi: jak zrobić żeby czekał na odpowiedź po powiedzeniu swojej kwestii?
Robione jako WinForm
Tutaj cały kod
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
namespace Voice_Recognition_Test1
{
public partial class Form1 : Form
{
SpeechRecognitionEngine RecEng = new SpeechRecognitionEngine();
SpeechSynthesizer Jan = new SpeechSynthesizer();
SpeechRecognitionEngine startlistening = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void VREn_Click(object sender, EventArgs e)
{
RecEng.RecognizeAsync(RecognizeMode.Multiple);
VRDis.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
commands.Add(new string [] { "Hi","What's up","Print my name","Wall","Table" });
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
RecEng.LoadGrammarAsync(grammar);
RecEng.SetInputToDefaultAudioDevice();
RecEng.SpeechRecognized += RecEng_SpeechRecognized;
}
void RecEng_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string speech = e.Result.Text;
if (speech == "Hi")
{
Jan.SpeakAsync("Hello there");
}
if (speech == "What's up")
{
Jan.SpeakAsync("Everything is fine, how about you?");
}
if (speech == "Print my name")
{
Jan.SpeakAsync("Who do I have the pleasure of talking to?");
RecEng.RecognizeAsyncStop();
switch (e.Result.Text)
{
case "Wall":
richTextBox1.Text += "\nSebastian";
break;
case "Table":
richTextBox1.Text += "\nAleksandra";
break;
default:
MessageBox.Show("ERROR!"); break;
}
}
string message = speech;
MessageBox.Show(message);
}
private void VRDis_Click(object sender, EventArgs e)
{
RecEng.RecognizeAsyncStop();
VRDis.Enabled = false;
}
}
}