首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微软语音识别:结果与信心得分交替?

微软语音识别:结果与信心得分交替?
EN

Stack Overflow用户
提问于 2013-09-23 17:26:03
回答 1查看 1.9K关注 0票数 4

我刚开始使用Microsoft.Speech识别器(使用11),我试图让它从一个简单的语法中输出n个最佳识别匹配,以及每个语法的可信度分数。

根据文档(和前面提到的in the answer to this question),人们应该能够使用e.Result.Alternates来访问得分最高的单词以外的其他可识别的单词。然而,即使在将置信度拒绝阈值重置为0之后(这意味着没有任何结果被拒绝),我仍然只能得到一个结果,并且没有备选结果(尽管SpeechHypothesized事件表明至少有一个其他单词似乎在某个时候被识别为非零置信度)。

我的问题是:有人能向我解释为什么我只得到一个公认的词,即使置信度被设定为零?我怎样才能得到其他可能的比赛和他们的信心得分?我在这里错过了什么?

下面是我的密码。预先感谢任何能帮忙的人:)

在下面的示例中,识别器被发送一个单词"news“的wav文件,并且必须从类似的单词("noose","newts")中选择。我想为每个单词提取一个识别者的信心分数的列表(它们都应该是非零的),即使结果它只会返回最好的一个(“新闻”)。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Recognition;

namespace SimpleRecognizer
{
    class Program
    {
        static readonly string[] settings = new string[] {
            "CFGConfidenceRejectionThreshold",
            "HighConfidenceThreshold", 
            "NormalConfidenceThreshold",
            "LowConfidenceThreshold"};

        static void Main(string[] args)
        {
            // Create a new SpeechRecognitionEngine instance.
            SpeechRecognitionEngine sre = new SpeechRecognitionEngine(); //en-US SRE

            // Configure the input to the recognizer.
            sre.SetInputToWaveFile(@"C:\Users\Anjana\Documents\news.wav");

            // Display Recognizer Settings (Confidence Thresholds)
            ListSettings(sre);

            // Set Confidence Threshold to Zero (nothing should be rejected)
            sre.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 0);
            sre.UpdateRecognizerSetting("HighConfidenceThreshold", 0);
            sre.UpdateRecognizerSetting("NormalConfidenceThreshold", 0);
            sre.UpdateRecognizerSetting("LowConfidenceThreshold", 0);

            // Display New Recognizer Settings
            ListSettings(sre);

            // Build a simple Grammar with three choices
            Choices topics = new Choices();
            topics.Add(new string[] { "news", "newts", "noose" });
            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(topics);
            Grammar g = new Grammar(gb);
            g.Name = "g";

            // Load the Grammar
            sre.LoadGrammar(g);

            // Register handlers for Grammar's SpeechRecognized Events
            g.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(gram_SpeechRecognized);

            // Register a handler for the recognizer's SpeechRecognized event.
            sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

            // Register Handler for SpeechHypothesized
            sre.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(sre_SpeechHypothesized);

            // Start recognition.
            sre.Recognize();

            Console.ReadKey(); //wait to close

        }
        static void gram_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            Console.WriteLine("\nNumber of Alternates from Grammar {1}: {0}", e.Result.Alternates.Count.ToString(), e.Result.Grammar.Name);
            foreach (RecognizedPhrase phrase in e.Result.Alternates)
            {
                Console.WriteLine(phrase.Text + ", " + phrase.Confidence);
            }
        }
        static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            Console.WriteLine("\nSpeech recognized: " + e.Result.Text + ", " + e.Result.Confidence);
            Console.WriteLine("Number of Alternates from Recognizer: {0}", e.Result.Alternates.Count.ToString());
            foreach (RecognizedPhrase phrase in e.Result.Alternates)
            {
                Console.WriteLine(phrase.Text + ", " + phrase.Confidence);
            }
        }
        static void sre_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
        {
            Console.WriteLine("Speech from grammar {0} hypothesized: {1}, {2}", e.Result.Grammar.Name, e.Result.Text, e.Result.Confidence);
        }
        private static void ListSettings(SpeechRecognitionEngine recognizer)
        {
            foreach (string setting in settings)
            {
                try
                {
                    object value = recognizer.QueryRecognizerSetting(setting);
                    Console.WriteLine("  {0,-30} = {1}", setting, value);
                }
                catch
                {
                    Console.WriteLine("  {0,-30} is not supported by this recognizer.",
                      setting);
                }
            }
            Console.WriteLine();
        }
    }
}

这提供了以下输出:

代码语言:javascript
复制
Original recognizer settings:
  CFGConfidenceRejectionThreshold = 20
  HighConfidenceThreshold        = 80
  NormalConfidenceThreshold      = 50
  LowConfidenceThreshold         = 20

Updated recognizer settings:
  CFGConfidenceRejectionThreshold = 0
  HighConfidenceThreshold        = 0
  NormalConfidenceThreshold      = 0
  LowConfidenceThreshold         = 0

Speech from grammar g hypothesized: noose, 0.2214646
Speech from grammar g hypothesized: news, 0.640804

Number of Alternates from Grammar g: 1
news, 0.9208503

Speech recognized: news, 0.9208503
Number of Alternates from Recognizer: 1
news, 0.9208503

我还试着用一个单独的短语来实现这一点(而不是一个有三个选择的短语),甚至每个单词/短语都有一个单独的语法。结果基本上是一样的:只有一个“交替”。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-23 22:15:49

我相信这是SAPI允许您请求SR引擎不支持的东西的另一个地方。

Microsoft.Speech.Recognition和System.Speech.Recognition都使用底层的SAPI接口来完成他们的工作;唯一的区别是使用了哪个SR引擎。(Microsoft.Speech.Recognition使用服务器引擎;System.Speech.Recognition使用桌面引擎。)

交替词主要是为听写而设计的,而不是上下文无关的语法。您总是可以为CFG获得一个备用的,但是替代的生成代码看起来不会扩展CFG的备用代码。

不幸的是,Microsoft.Speech.Recognition引擎不支持听写。(然而,它的工作音频质量要低得多,而且不需要培训。)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18965286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档