⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reco.cpp

📁 英语学习的软件说明
💻 CPP
字号:
#include "stdafx.h"
#include <sphelper.h>
#include "Reco.h"

CRecoApp::CRecoApp()
{
	
};

BOOL CRecoApp::InitInstance()
{
  CoInitialize(NULL);
  return TRUE;
}

CRecoApp RecoApp;

CRecoApp::InitSAPI( HWND hWnd )
{
    HRESULT hr = S_OK;
    CComPtr<ISpAudio> cpAudio;

    while ( 1 )
    {
        hr = g_cpEngine.CoCreateInstance(CLSID_SpSharedRecognizer);
        if ( FAILED( hr ) )
        {
            break;
        }
       
        hr = g_cpEngine->CreateRecoContext( &g_cpRecoCtxt );
        if ( FAILED( hr ) )
        {
            break;
        }

        hr = g_cpRecoCtxt->SetNotifyWindowMessage( hWnd, WM_RECOEVENT, 0, 0 );
        if ( FAILED( hr ) )
        {
            break;
        }

        hr = g_cpRecoCtxt->SetInterest( SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION) );
        if ( FAILED( hr ) )
        {
            break;
        }

        hr = g_cpRecoCtxt->CreateGrammar(NULL, &g_cpCmdGrammar);
        if (FAILED(hr))
        {
            break;
        }
        hr = g_cpCmdGrammar->LoadCmdFromFile(L"reco.xml",SPLO_DYNAMIC);
        if ( FAILED( hr ) )
        {
            break;
        }

        hr = g_cpCmdGrammar->SetRuleState(NULL, NULL, SPRS_ACTIVE );
        if ( FAILED( hr ) )
        {
            break;
        }

        break;
    }

    if ( FAILED( hr ) )
    {	
        CleanupSAPI();
    }
    return ( hr );
}

CRecoApp::CleanupSAPI( void )
{
    if ( g_cpCmdGrammar )
    {
        g_cpCmdGrammar.Release();
    }
    if ( g_cpRecoCtxt )
    {
        g_cpRecoCtxt->SetNotifySink(NULL);
        g_cpRecoCtxt.Release();
    }
	if ( g_cpEngine )
	{
		g_cpEngine.Release();
	}
}

CRecoApp::ProcessRecoEvent( HWND hWnd )
{
    CSpEvent event;

    while (event.GetFrom(g_cpRecoCtxt) == S_OK)
    {
        if (event.eEventId == SPEI_RECOGNITION)
		{
			ISpPhrase *pPhrase;
			SPPHRASE *pElements;
			ULONG resultid;

            pPhrase = event.RecoResult();
			pPhrase->GetPhrase(&pElements);
			resultid = pElements->Rule.ulId;
			PostMessage(hWnd,WM_RECOGNIZED,WPARAM(resultid),0);
        }
    }
}

CRecoApp::traincmd(HWND hWnd)
{
	g_cpEngine->DisplayUI(hWnd, NULL, SPDUI_UserTraining, NULL, 0);
}

CRecoApp::miccmd(HWND hWnd)
{
	g_cpEngine->DisplayUI(hWnd, NULL, SPDUI_MicTraining, NULL, 0);
}

CRecoApp::recocmd(HWND hWnd)
{
	g_cpEngine->DisplayUI(hWnd, NULL, SPDUI_RecoProfileProperties, NULL, 0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -