一个超简单的语音识别编程,听写程序

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                 

CSpeechRecognition类封装了语音识别操作所需调用的几个接口,使用它进行语音识别编程很方便,也很简洁。

CSpeechRecognition类的定义如下:

///

// active speech engine

#include <atlbase.h>

extern CComModule _Module;

#include <atlcom.h>

#include <sapi.h>

#include <sphelper.h>

#include <spuihelp.h>

///

// speech message

#define WM_SREVENT   WM_USER+102

 

class CSpeechRecognition 

{

public:

   CSpeechRecognition();

   virtual ~CSpeechRecognition();

 

   // initialize

   BOOL Initialize(HWND hWnd = NULL, BOOL bIsShared = TRUE);

   void Destroy();

 

   // start and stop

   BOOL Start();

   BOOL Stop();

   BOOL IsDictationOn()

   {

       return m_bOnDictation;

   }

 

   // event handler

   void GetText(WCHAR **ppszCoMemText, ULONG ulStart = 0, ULONG nlCount = -1);

 

   // voice training

   HRESULT VoiceTraining(HWND hWndParent);

 

   // microphone setup

   HRESULT MicrophoneSetup(HWND hWndParent);

 

   // token list

   HRESULT InitTokenList(HWND hWnd, BOOL bIsComboBox = FALSE);

 

   // error string

   CString GetErrorString()

   {

       return m_sError;

   }

 

   // interface

     CComPtr<ISpRecognizer> m_cpRecoEngine;  // SR engine

       CComPtr<ISpRecoContext> m_cpRecoCtxt;   //Recognition contextfor dictation

     CComPtr<ISpRecoGrammar> m_cpDictationGrammar;  // Dictation grammar

 

private:

   CString m_sError;

    BOOL    m_bOnDictation;

};

其中定义的消息WM_SREVENT用于指示语音识别事件,该消息将通知到函数指定的响应窗口。

类中定义了3个接口指针m_cpRecoEnginem_cpRecoCtxtm_cpDictationGrammar,分别用于引用语音识别引擎3个重要接口IspRecognizerISpRecoContextIspRecoGrammar

函数Initialize语音识别引擎基本工作环境包括引擎识别上下文语法音频事件等的

BOOL CSpeechRecognition::Initialize(HWND hWnd, BOOL bIsShared)

{

   // com library

   if (FAILED(CoInitialize(NULL)))

   {

       m_sError=_T("Error intialization COM");

       return FALSE;

   }

 

   // SR engine

    HRESULT hr = S_OK;

    if (bIsShared)

    {

        // Shared reco engine.

        // For a shared reco engine, the audio gets setup automatically

        hr = m_cpRecoEngine.CoCreateInstance( CLSID_SpSharedRecognizer );

    }

   else

   {

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值