【问题标题】:How to get NBest alternatives with azure speech-to-text如何使用 azure Speech-to-Text 获得 NBest 替代品
【发布时间】:2022-03-16 19:11:01
【问题描述】:

我希望使用 azure Speech-to-Text 为单个语音语句获取多个替代转录。

我已经设置了 format=detailed 参数,并且响应确实包含一个名为 NBest 的字段。但该字段仅包含一个转录。

我还需要在输入端设置什么吗?

谢谢。

【问题讨论】:

  • 您能否添加更多关于您正在使用的 API 表面(REST 与认知服务库)的详细信息?

标签: azure-speech


【解决方案1】:

我加入评论以确保您使用的是什么机制:

  1. REST API for short audio
  2. Speech SDK

如果您正在使用Speech CLI 或想尝试一下,请执行以下操作:

第一组:

spx config recognize @default.output --set @@output.all.detailed

然后:

spx recognize --file FILE --output all itn text --output all file type json

spx recognize --file FILE --output all lexical text --output all file type json

【讨论】:

    【解决方案2】:

    我相信你已经定义了所有需要在输入端定义的东西。

    但有了更多关于周围环境的信息,就更容易弄清楚如何准确回答。例如,我不确定它在 ContinuousRecognition 模式或 RecognizeOnce 模式下的行为是否相同。

    在以下 C# 代码中,我确实获得了 NBest 数组包含 5 个结果的结果。但是请注意,在我找到的代码示例中,您将在下面找到与我自己的集成的代码示例,NBest 属性被定义为一个列表。我不确定在您使用的框架中,这是否可能是包含单个结果的 NBest 对象的来源。

    SpeechConfig _speechConfig = SpeechConfig.FromSubscription(SUBSCRIPTION_KEY, SUBSCRIPTION_REGION);
    _speechConfig.SpeechRecognitionLanguage = SPEECH_RECOGNITION_LANGUAGE;
    _speechConfig.OutputFormat = OutputFormat.Detailed;
    
    AudioConfig _audioConfig = AudioConfig.FromDefaultMicrophoneInput();
    _recognizer = new SpeechRecognizer(_speechConfig, _audioConfig);
    
    _recognizer.Recognized += (s, e) => OnRecognized(e);
    
        private void OnRecognized(SpeechRecognitionEventArgs e)
        {
            if (e.Result.Reason == ResultReason.RecognizedSpeech)
            {
                SpeechRecognitionResult result = e.Result;
                PropertyCollection propertyCollection = result.Properties;
                string jsonResult = propertyCollection.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
                var structuredResult = JsonConvert.DeserializeObject<Result>(jsonResult);
                var bestResult = structuredResult?.NBest[0]; // <= pick your favorite NBest
                // Do something with the bestResult of your choice
            }
        }
    
        public class Word
        {
            public int Duration { get; set; }
            public int Offset { get; set; }
            public string word { get; set; }
        }
    
        public class NBest
        {
            public double Confidence { get; set; }
            public string Display { get; set; }
            public string ITN { get; set; }
            public string Lexical { get; set; }
            public string MaskedITN { get; set; }
            public List<Word> Words { get; set; }
        }
    
        public class Result
        {
            public string DisplayText { get; set; }
            public int Duration { get; set; }
            public string Id { get; set; }
            public List<NBest> NBest { get; set; }
            public Int64 Offset { get; set; }
            public string RecognitionStatus { get; set; }
        }
    

    【讨论】:

      【解决方案3】:

      回答这个问题(如果使用 REST API):

      根据微软员工于 2021 年 9 月 1 日撰写的 Microsoft 文档,如果您使用 REST API,则只能获得一个替代品:

      “其余 API 只返回最好的结果。这个 api 的行为已经很长时间没有变化了。”

      见: https://docs.microsoft.com/en-us/answers/questions/534368/azure-speech-to-text-how-to-receive-nbext-with-res.html

      这很不寻常,因为 Microsoft 自己的 REST API for Short Audio 文档显示了包含两 (2) 个替代项的“样本返回”。

      【讨论】:

        猜你喜欢
        • 2019-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-14
        • 2019-11-12
        • 2021-01-31
        • 1970-01-01
        相关资源
        最近更新 更多