代码之家  ›  专栏  ›  技术社区  ›  ladenedge

MS Speech Platform 11识别器是否支持ARPA编译的语法?

  •  10
  • ladenedge  · 技术社区  · 7 年前

    我能够编译一个ARPA文件——例如,一个很小的例子 provided by Microsoft

    CompileGrammar.exe -In stock.arpa -InFormat ARPA
    

    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);
    }
    

    此测试通过,但请注意它使用 EmulateRecognize()

    using (var engine = new SpeechRecognitionEngine(new CultureInfo("en-US"))) 
    {
        engine.LoadGrammar(new Grammar("stock.cfg"));
        engine.SetInputToWaveFile("go-up.wav");
        var result = engine.Recognize();
    }
    

    结果

    微软 states quite clearly

    2 回复  |  直到 7 年前
        1
  •  3
  •   seiya1223    6 年前

    回答你的问题

    MS Speech Platform 11识别器是否支持ARPA编译 语法?

    答案是肯定的。

    文化/语法/波形 . 我不知道你的完整代码,但根据我的测试和演示代码,我猜根本原因是我们需要处理 演讲稿 在我们这边,你可能还没有做到。

    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;
            }
    

    enter image description here enter image description here

    股票会涨吗

    更多信息: https://docs.microsoft.com/en-us/dotnet/api/system.speech.recognition.speechrecognitionengine.setinputtowavefile?redirectedfrom=MSDN&view=netframework-4.7.2#System_Speech_Recognition_SpeechRecognitionEngine_SetInputToWaveFile_System_String_

        2
  •  1
  •   ladenedge    6 年前

    What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition?

    系统语音(桌面版)

    seiya1223's answer . 这里的示例代码非常有效。

    Microsoft.Speech (服务器版本)

    可能是因为服务器版本不包含“听写引擎”,所以微软.演讲图书馆显然永远不会 比赛 一个ARPA来源的CFG。然而,它仍然会 假设 通过电话说了什么 SpeechRecognitionRejected

    1. 将using语句从系统语音至微软.演讲,当然。
    2. SpeechRecognition拒绝
    3. 在事件处理程序中,检查 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代码的输出,但是使用了所有可用的事件处理程序和一堆额外的日志(重点是我的):

    正在启动异步识别。。。


    在Speech假想处理程序中:


    -语法名称=股票;结果文本=遗嘱

    -语法名称=股票;结果文本=股票
    在Speech假想处理程序中:

    在Speech假想处理程序中:

    在SpeechRecognitionRejectedHandler中:
    -语法名称=股票;结果文本=股票会上涨吗


    -AudioPosition=00:00:03.2000000;InputStreamEnded=True


    推荐文章