【发布时间】:2023-03-20 16:20:01
【问题描述】:
我正在尝试在我的 Windows 8 上使用 C# (4.5) 上的语音识别库。
我安装了“Microsoft Speech Platform SDK 11”,但使用 LoadGrammar 收到异常。
我的程序:
using System;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SpeechRecognition
{
class Program
{
static void Main(string[] args)
{
// Create an in-process speech recognizer for the en-US locale.
using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine())
{
// Create and load a dictation grammar.
// An unhandled exception of type 'System.UnauthorizedAccessException' occurred in System.Speech.dll
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Recognized text: " + e.Result.Text);
}
}
}
System.Speech.dll 中出现“System.UnauthorizedAccessException”类型的未处理异常
堆栈跟踪:
他们 System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer 识别器,布尔 inproc) em System.Speech.Recognition.SpeechRecognitionEngine.get_RecoBase() em System.Speech.Recognition.SpeechRecognitionEngine.LoadGrammar(语法 语法) em SpeechRecognition.Program.Main(String[] args) na e:\TestCenter\SpeechRecognition\SpeechRecognition\Program.cs:linha 23 em System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集, 字符串[] args) em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 preserveSyncCtx) 时间 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 preserveSyncCtx) 时间 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、Object 状态)
我在Win7和Win8下测试过,但是没有一个能用。
有人可以帮我吗?
【问题讨论】:
-
这不是导致您的问题的代码。不可能从中得到那个错误。
-
我想你忘了在文件开头使用这两行:
using System;和using System.Speech.Recognition; -
@AndrewBarber 确实如此。这是我的代码的第一行。
-
@Oliboy50 实际上我正在使用(使用 System;使用 System.Speech.Recognition;使用 System.Speech.Synthesis;)。 =/
-
@Crasher 这可能是第一行,但不可能是导致该错误的行。
标签: c# windows-8 speech-recognition