【发布时间】:2018-08-13 14:18:25
【问题描述】:
我不知道我们是否可以创建控制台应用程序用于语音识别(搜索相同但没有找到任何答案)并尝试了此代码。
我有这段代码在 winforms 应用程序中工作
但是当试图在控制台 Visual Studio 中创建这个应用程序时,会给出一个非常奇怪的错误 mscorelib.pdb not found.And transfer to a page mscorelib.pdb
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
namespace ConsoleApplication2
{
public class Program
{
public static void Main(string[] args)
{
tester tst = new tester();
tst.DoWorks();
}
}
public class tester
{
SpeechSynthesizer ss = new SpeechSynthesizer();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
PromptBuilder pb = new PromptBuilder();
Choices clist = new Choices();
public void DoWorks()
{
clist.Add(new string[] { "how are you", "what is the current time", "open chrome", "hello" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SetInputToDefaultAudioDevice();
sre.SpeechRecognized += sre_recognised;
sre.RecognizeAsync(RecognizeMode.Multiple);
}
public void sre_recognised(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text.ToString())
{
case "hello":ss.SpeakAsync("Hello shekar");
break;
case "how are you": ss.SpeakAsync("I am fine and what about you");
break;
case "what is the time":ss.SpeakAsync("current time is: " + DateTime.Now.ToString());
break;
case "open chrome":System.Diagnostics.Process.Start("chrome", "wwe.google.com");
break;
default: ss.SpeakAsync("thank you");
break;
}
Console.WriteLine(e.Result.Text.ToString());
}
}
}
这是错误页面的快照
我还加载了给定选项“Microsoft.symbol.Server”,但它仍然给出相同的输出。
编辑
这里是输出窗口
输出很长,所以无法显示所有输出,捕获了一些相关部分(遗憾)。
【问题讨论】:
-
这不是真正的错误。这只是一个警告说找不到调试数据。实际的例外情况有所不同。查看输出窗口和堆栈跟踪
-
尝试用属性
[STAThread]装饰[STAThread] -
@Crowcoder [STAThred] 也给出了相同的输出。
-
您很可能还必须防止程序过早退出。在 WinForms 应用程序中,您会自动拥有它。如果您没有某种循环或等待句柄,控制台程序将退出...
-
正如@Fildor 所说,阻止应用退出。如果在调用
tst.DoWorks()之后添加Console.ReadLine()语句会发生什么
标签: c# .net speech-recognition text-to-speech speech-synthesis