Speech recognition MS语音平台11识别器是否支持ARPA编译语法?
如何在MS语音中使用ARPA文件?Microsoft Speech Platform 11识别器的文档说明可以从ARPA文件编译语法 我能够使用以下命令行编译ARPA文件(例如,一个小示例):Speech recognition MS语音平台11识别器是否支持ARPA编译语法?,speech-recognition,sapi,microsoft-speech-platform,Speech Recognition,Sapi,Microsoft Speech Platform,如何在MS语音中使用ARPA文件?Microsoft Speech Platform 11识别器的文档说明可以从ARPA文件编译语法 我能够使用以下命令行编译ARPA文件(例如,一个小示例): CompileGrammar.exe -In stock.arpa -InFormat ARPA 我能够在以下测试中使用生成的CFG文件: using Microsoft.Speech.Recognition; // ... using (var engine = new SpeechRecogni
CompileGrammar.exe -In stock.arpa -InFormat ARPA
我能够在以下测试中使用生成的CFG文件:
using Microsoft.Speech.Recognition;
// ...
using (var engine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
engine.LoadGrammar(new Grammar("stock.cfg"));
var result = engine.EmulateRecognize("will stock go up");
Assert.That(result, Is.Not.Null);
}
此测试通过,但请注意,它使用了仿真认知()
。当我切换到使用实际音频文件时,如下所示:
using (var engine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
engine.LoadGrammar(new Grammar("stock.cfg"));
engine.SetInputToWaveFile("go-up.wav");
var result = engine.Recognize();
}
结果始终为空,测试失败
微软表示它是受支持的,但即使是非常简单的例子也似乎不起作用。我做错了什么?关于你的问题:
MS语音平台11识别器是否支持ARPA编译
语法
答案是肯定的
在我这方面使用了代码,只需更改三个属性:文化/语法/波形文件。我不知道您的完整代码,但根据我的测试和演示代码,我想根本原因是我们需要处理我们这边的SpeechRecognited,而您这边可能没有这样做
static bool completed;
static void Main(string[] args)
{
// Initialize an in-process speech recognition engine.
using (SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(new CultureInfo("en-us")))
{
// Create and load a grammar.
Grammar dictation = new Grammar("stock.cfg");
dictation.Name = "Dictation Grammar";
recognizer.LoadGrammar(dictation);
// Configure the input to the recognizer.
recognizer.SetInputToWaveFile("test.wav");
// Attach event handlers for the results of recognition.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.RecognizeCompleted +=
new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
// Perform recognition on the entire file.
Console.WriteLine("Starting asynchronous recognition...");
completed = false;
recognizer.RecognizeAsync();
// Keep the console window open.
while (!completed)
{
Console.ReadLine();
}
Console.WriteLine("Done.");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result != null && e.Result.Text != null)
{
Console.WriteLine(" Recognized text = {0}", e.Result.Text);
}
else
{
Console.WriteLine(" Recognized text not available.");
}
}
// Handle the RecognizeCompleted event.
static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
if (e.Error != null)
{
Console.WriteLine(" Error encountered, {0}: {1}",
e.Error.GetType().Name, e.Error.Message);
}
if (e.Cancelled)
{
Console.WriteLine(" Operation cancelled.");
}
if (e.InputStreamEnded)
{
Console.WriteLine(" End of stream encountered.");
}
completed = true;
}
静态bool完成;
静态void Main(字符串[]参数)
{
//初始化进程内语音识别引擎。
使用(语音识别引擎识别器=
新的SpeechRecognitionEngine(新文化信息(“美国”))
{
//创建并加载语法。
语法听写=新语法(“stock.cfg”);
听写。Name=“听写语法”;
识别器。加载语法(听写);
//配置识别器的输入。
setInputToWave文件(“test.wav”);
//为识别结果附加事件处理程序。
识别器+=
新的EventHandler(识别器\语音识别器);
识别器。识别器已完成+=
新的EventHandler(识别器识别完成);
//对整个文件执行识别。
WriteLine(“启动异步识别…”);
完成=错误;
RecognizeAsync();
//保持控制台窗口打开。
而(!已完成)
{
Console.ReadLine();
}
控制台。WriteLine(“完成”);
}
Console.WriteLine();
Console.WriteLine(“按任意键退出…”);
Console.ReadKey();
}
//处理SpeechReceigned事件。
静态无效识别器\u SpeechRecognited(对象发送器,SpeechRecognitedEventArgs e)
{
如果(e.Result!=null&&e.Result.Text!=null)
{
WriteLine(“识别的文本={0}”,e.Result.text);
}
其他的
{
Console.WriteLine(“识别文本不可用”);
}
}
//处理RecognizeCompleted事件。
静态无效识别器\u RecognizeCompleted(对象发送方,RecognizeCompletedEventArgs e)
{
如果(例如错误!=null)
{
WriteLine(“遇到错误,{0}:{1}”,
e、 Error.GetType().Name,e.Error.Message);
}
如果(如已取消)
{
控制台写入线(“操作已取消”);
}
如果(如输入流)
{
WriteLine(“遇到流结束”);
}
完成=正确;
}
wav的内容只是“股票会上涨”(持续时间约为2秒)
有关更多信息:
根据您使用的Microsoft Speech SDK的版本,此问题有两种不同的答案。(见:) 系统语音(桌面版) 在本例中,请参见。那里的示例代码非常有效 Microsoft.Speech(服务器版本) 也许是因为服务器版本不包括“听写引擎”,微软的.Speech库显然永远不会匹配ARPA源的CFG。然而,它仍然会假设通过
SpeechRecognitionRejected
事件所说的话。以下是seiya1223桌面代码的必要更改:
SpeechRecognitionRejected
事件添加事件处理程序e.Result.Text
属性以获取最终假设static string transcription;
static void Main(string[] args)
{
using (var recognizer = new SpeechRecognitionEngine(new CultureInfo("en-us")))
{
engine.SpeechRecognitionRejected += SpeechRecognitionRejectedHandler;
// ...
}
}
void SpeechRecognitionRejectedHandler(object sender, SpeechRecognitionRejectedEventArgs e)
{
if (e.Result != null && !string.IsNullOrEmpty(e.Result.Text))
transcription = e.Result.Text;
}
此处理程序在识别结束时调用一次。例如,下面是seiya1223代码的输出,但使用了所有可用的事件处理程序和一系列额外的日志记录(emphasis mine):
正在启动异步识别…在SpeechDetectedHandler中:
-AudioPosition=00:00:01.2300000
在SpeechAspectizedHandler中:
-语法名称=股票;结果文本=Go
在SpeechAspectizedHandler中:
-语法名称=股票;结果文本=将
在SpeechAspectizedHandler中:
-语法名称=股票;结果文本=将储存
在SpeechAspectizedHandler中:
-语法名称=股票;结果文本=库存是否会继续
在SpeechAspectizedHandler中:
-语法名称=股票;结果文本=股票会上涨吗
在SpeechRecognitionRejectedHandler中:
-语法名称=股票;结果文本=股票是否会上涨
在已识别的CompletedHandler中。
-AudioPosition=00:00:03.2000000;InputStreamEnded=True
-没有结果。
完成。
您是否有使用SRGS格式的工作识别器?有许多吹毛求疵的细节