该程序使用语音识别,并以Jarvis为基础。我希望能够使用不同语言进行语音识别,例如丹麦语和英语。我的问题是我没有得到任何回应。我似乎无法弄清楚我是否得到了回复,或者即使检测到并阅读了该语音。
public partial class Form1 : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer Dexter = new SpeechSynthesizer();
string QEvent;
string ProcWindow;
double timer = 10;
int count = 1;
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new DictationGrammar());
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Commands.txt")))));
_recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
int ranNum = rnd.Next(1, 10);
string speech = e.Result.Text;
switch (speech)
{
//GREETINGS
case "Hey Dexter":
case "Hej Dexter":
if (ranNum < 6) { Dexter.Speak("Hej sir"); }
else if (ranNum > 5) { Dexter.Speak("Hej"); }
break;
case "Shut down Dexter":
case "Luk ned Dexter":
Dexter.Speak("Så ses vi");
Close();
break;
case "Dexter":
if (ranNum < 5) { QEvent = ""; Dexter.Speak("Ye sir"); }
else if (ranNum > 4) { QEvent = ""; Dexter.Speak("Ye"); }
break;
}
}
}