如何在Microsoft.Speech中使用DTMFRecognitionEngine类 [英] How to use the DTMFRecognitionEngine class in Microsoft.Speech

查看:92
本文介绍了如何在Microsoft.Speech中使用DTMFRecognitionEngine类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft.Speech SDK具有

The Microsoft.Speech SDK has a DTMFRecognitionEngine class, which I'd like to experiment with - we need to detect DTMF tones within a WAV file (I realise there are other ways to do this, but I'm evaluating all possible methods).

有关如何实际使用该类的文档尚不清楚:它是伴随类SpeechRecognitionEngine,它具有大量示例和清晰易懂的方法,例如SetInputToWaveFile. DTMFRecognitionEngine没有任何此类方法.

The documentation isn't clear on how to actually use the class: it's companion class, SpeechRecognitionEngine, has plenty of examples and nice clear methods like SetInputToWaveFile. DTMFRecognitionEngine doesn't have any such methods.

有人可以提供有关如何在自己的代码中使用此组件的见解吗?

Could someone provide insight on how I can use this component in my own code?

:似乎没有任何方法可以将此类用于... ...,实际上,还有很多事情.我正在寻找一个允许我检测音频文件中DTMF数字的位置和持续时间的库.我看过 TapiEx ,但是他们没有回复电子邮件.如果有人有其他建议,我们将不胜感激...

It appears that there isn't any way to use this class for ... well, anything much really. I'm looking for a library that will allow me to detect the position and duration of DTMF digits in an audio file. I've looked at TapiEx, but they're not responding to emails. If anyone has any other suggestions, they'd be gratefully received...

推荐答案

看来这是不可能的.我什至还获得了DtmfRecognitionEngine的私有_engine,它是SpeechRecognitionEngine的包装器,没有运气就调用了它的SetInputToWaveFile.显然,向DtmfRecognitionEngine发出提示音的唯一方法是调用AddTone().我提供了一个示例语法文件和一些可以使用的源代码.有趣的是,如果取消对dre.AddTone()的注释,则将同时看到sre的事件和dre的事件都被触发.

It would appear that this is not possible. I even went so far as to get the private _engine of DtmfRecognitionEngine which is a wrapper the SpeechRecognitionEngine and call its SetInputToWaveFile with no luck. Apparently the only way to get a tone into the DtmfRecognitionEngine is to call AddTone(). I've included a sample grammar file and some source code that you can play with. Interestingly, if you uncomment the dre.AddTone()'s you see both sre's events and dre's events are getting fired.

将呼叫切换到sre.RecognizeAsync()无济于事.

Switching the call to sre.RecognizeAsync() does not help.

好像您需要一个不同的库...

Looks like you'll need a different library...

PinGrammar.xml

PinGrammar.xml

<?xml version="1.0"?>
<grammar mode="dtmf" version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.w3.org/2001/06/grammar 
                             http://www.w3.org/TR/speech-grammar/grammar.xsd"
         xmlns="http://www.w3.org/2001/06/grammar"
         root="pin">

  <rule id="digit">
    <one-of>
      <item> 0 </item>
      <item> 1 </item>
      <item> 2 </item>
      <item> 3 </item>
      <item> 4 </item>
      <item> 5 </item>
      <item> 6 </item>
      <item> 7 </item>
      <item> 8 </item>
      <item> 9 </item>
    </one-of>
  </rule>

  <rule id="pin" scope="public">
    <one-of>
      <item>
        <item repeat="4">
          <ruleref uri="#digit"/>
        </item>
        #
      </item>
      <item>
        * 9
      </item>
    </one-of>
  </rule>

</grammar>

来源:

using Microsoft.Speech.Recognition;
using System.Reflection;

namespace DTMF_Recognition
{
    class Program
    {
        static void Main(string[] args)
        {
            Grammar grammar = null;
            grammar = new Grammar("PinGrammar.xml");

            DtmfRecognitionEngine dre = new DtmfRecognitionEngine();
            dre.DtmfRecognized += dre_DtmfRecognized;

            FieldInfo field = typeof(DtmfRecognitionEngine).GetField("_engine", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
            var wrapper = field.GetValue(dre);
            FieldInfo engineField = wrapper.GetType().GetField("_engine", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
            SpeechRecognitionEngine sre = (SpeechRecognitionEngine)engineField.GetValue(wrapper);

            dre.DtmfHypothesized += dre_DtmfHypothesized;
            dre.DtmfRecognitionRejected += dre_DtmfRecognitionRejected;
            dre.RecognizeCompleted += dre_RecognizeCompleted;
            dre.LoadGrammar(grammar);

            //dre.AddTone(DtmfTone.One);
            //dre.AddTone(DtmfTone.Two);
            //dre.AddTone(DtmfTone.Three);
            //dre.AddTone(DtmfTone.Four);
            //dre.AddTone(DtmfTone.Hash);

            sre.SetInputToWaveFile(@"C:\Users\Clay Ver Valen\Desktop\3.wav");
            sre.SpeechHypothesized += sre_SpeechHypothesized;
            sre.SpeechDetected += sre_SpeechDetected;
            sre.SpeechRecognitionRejected += sre_SpeechRecognitionRejected;

            dre.RecognizeAsync();
            System.Threading.Thread.Sleep(30000);
        }

        static void sre_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            int i = 1;
        }

        static void sre_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
        {
            int i = 1;
        }

        static void sre_SpeechDetected(object sender, SpeechDetectedEventArgs e)
        {
            int i = 1;
        }

        static void dre_DtmfRecognitionRejected(object sender, DtmfRecognitionRejectedEventArgs e)
        {
            int i = 1;
        }

        static void dre_DtmfHypothesized(object sender, DtmfHypothesizedEventArgs e)
        {
            int i = 1;
        }

        static void dre_RecognizeCompleted(object sender, DtmfRecognizeCompletedEventArgs e)
        {
            int i = 1;
        }

        static void dre_DtmfRecognized(object sender, DtmfRecognizedEventArgs e)
        {
            int i = 1;
        }
    }
}

这篇关于如何在Microsoft.Speech中使用DTMFRecognitionEngine类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆