【发布时间】:2016-02-07 08:08:26
【问题描述】:
我有一个控制台应用程序,我在其中使用 System.Speech.Recognition。我想对着麦克风说话并接受文本。到目前为止,我成功了。但我有更多的句子,比如“你好吗?” “现在是几奌?”等等。应用程序可以识别所有这些,但在我拼出第一句话后它就退出了。我不希望这种情况发生,我希望该应用程序能够识别我在各种时间戳上拼写的所有句子。下面是我的代码:
class Program
{
static void Main(string[] args)
{
NaoSpeechRecognitionEntities db = new NaoSpeechRecognitionEntities();
var userInput = db.UserInputs.ToList();
//List<string> userReplies = new List<string>();
Choices userReplies = new Choices();
foreach (var reply in userInput)
{
userReplies.Add(reply.Reply);
}
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
GrammarBuilder gb = new GrammarBuilder();
gb.Append(userReplies);
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.SetInputToDefaultAudioDevice();
// Start recognition.
sre.Recognize();
}
static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//MessageBox.Show("Speech recognized: " + e.Result.Text);
CurrentReply.currentReply = e.Result.Text;
//NaoSpeechRecognitionEntities db = new NaoSpeechRecognitionEntities();
//var userInput = db.UserInputs.Where(ui=>ui.Reply==e.Result.Text).SingleOrDefault();
//var robotReply = db.RobotOutputs.Where(rp=>rp.UserInputId==userInput.UserInputId).SingleOrDefault();
//CurrentReply.currentReply = robotReply.Reply;
}
正如您所见,它是一个控制台应用程序,我在 Windows 窗体上进行了尝试,但到目前为止没有成功。我也试着把 sre.Recognize();在无限循环中,或者使用 goto 指令,但它仍然没有工作。
非常感谢任何帮助。 提前谢谢!
【问题讨论】:
-
我忘了说我想被识别的语句是通过 EF 从数据库中获取的,不是那么相关,而是为了让您更好地理解
标签: c# .net winforms console-application speech-to-text