嗨,我这里有情况,我不知道如何解决这个问题。这段代码很好,有 0 个错误,但每当我执行 F5 时,它都会向我显示一个没有语音且无法识别的空白表格,请帮忙。请我真的需要帮助有人可以帮助我。
现在这一行仅用于“看起来您的帖子主要是代码;请添加更多详细信息”;
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.Synthesis;
using System.Speech.Recognition;
using System.Threading;
namespace a.i
{
public partial class Form1 : Form
{
SpeechSynthesizer s = new SpeechSynthesizer();
Choices list = new Choices();
public Form1()
{
SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
list.Add(new String[] { "hello", "how are you" });
Grammar gr = new Grammar(new GrammarBuilder(list));
try
{
rec.RequestRecognizerUpdate();
rec.LoadGrammar(gr);
rec.SpeechRecognized += rec_SpeachRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
}
catch { return; }
s.SelectVoiceByHints(VoiceGender.Neutral);
s.Speak("Hello, my name is Gabriel ChatterBot");
InitializeComponent();
}
public void say(string h)
{
s.Speak(h);
}
private void rec_SpeachRecognized(object sender, SpeechRecognizedEventArgs e)
{
String r = e.Result.Text;
//what you say
if (r == "hello")
{
// what it says
say("hi");
}
//what you say
if (r == "how are you")
{
// what it says
say("Great, and you!");
}
}
}
}