viaVoice开发,怎样设置IBM viavoice的语言

来源:互联网 发布:如何在手机淘宝付款 编辑:程序博客网 时间:2024/05/20 05:26

#include <speech.h>
#include <mmsystem.h>
#include "reslist.hpp"

#define MAX_PHRASELEN 128


class SapiSpeech;
class Result;
class ResultsList;

typedef enum SpeechEventEnum
{
 ENG_ATTRIBCHANGED,
  ENG_INTERFERENCE,
  ENG_SOUND,
  ENG_UTTERANCEBEGIN,
  ENG_UTTERANCEEND,
  ENG_VUMETER,
  DCT_BOOKMARK,
  DCT_PAUSED,
  DCT_PHRASESTART,
  DCT_PHRASEHYPOTHESIS,
  DCT_PHRASEFINISH,
  DCT_REEVALUATE,
  DCT_TRAINING,
  DCT_UNARCHIVE,
} SPCHEVENTID;

typedef struct WantNotificationsStruct
{
 BOOL bEngAttribChanged;
 BOOL bEngInterference;
 BOOL bEngSound;
 BOOL bEngUtteranceBegin;
 BOOL bEngUtteranceEnd;
 BOOL bEngVUMeter;
 BOOL bDctBookmark;
 BOOL bDctPaused;
 BOOL bDctPhraseStart;
 BOOL bDctPhraseHypothesis;
 BOOL bDctPhraseFinish;
 BOOL bDctReevaluate;
 BOOL bDctTraining;
 BOOL bDctUnarchive;
} WantNotifications;

extern WantNotifications  tellMe; // notification bits to suppress/enable
extern const char   *pGStopPhr; // "stop dictation" phrase for various languages

//------------------------------------------------------------------------------
// Description: Dictation Grammar notification sink class definition
//------------------------------------------------------------------------------
class SpchDctSink : public ISRGramNotifySink
{
public:
 ResultsList      m_ResList;

public:
    SpchDctSink( SapiSpeech *pSpch);
    ~SpchDctSink();

    // IUnkown members that delegate to m_punkOuter
    // Non-delegating object IUnknown
    STDMETHODIMP         QueryInterface (REFIID, LPVOID FAR *);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // ISRNotifySink
 STDMETHODIMP BookMark         (DWORD);
 STDMETHODIMP Paused           ();
 STDMETHODIMP PhraseFinish     (DWORD, QWORD, QWORD, PSRPHRASE, LPUNKNOWN);
 STDMETHODIMP PhraseHypothesis (DWORD, QWORD, QWORD, PSRPHRASE, LPUNKNOWN);
 STDMETHODIMP PhraseStart      (QWORD);
 STDMETHODIMP ReEvaluate       (LPUNKNOWN);
 STDMETHODIMP Training         (DWORD);
 STDMETHODIMP UnArchive        (LPUNKNOWN);
 void         Cleanup();

protected:
    DWORD     m_dwRefCnt;
 SapiSpeech   *m_pSpchObj;
private:
};


//------------------------------------------------------------------------------
// Description: Engine notification sink class definition
//------------------------------------------------------------------------------
class SpchEngSink : public ISRNotifySink
{
public:
 DWORD     m_dwKey;  // key returned by engine when this not. is registered
          // is used when engine wants to unregister this notification

private:

public:
    SpchEngSink(SapiSpeech *pSpch);
    ~SpchEngSink();

    // IUnkown members that delegate to m_punkOuter
    // Non-delegating object IUnknown
    STDMETHODIMP         QueryInterface (REFIID, LPVOID FAR *);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // ISRNotifySink
 STDMETHODIMP AttribChanged  (DWORD);
 STDMETHODIMP Interference   (QWORD, QWORD, DWORD);
 STDMETHODIMP Sound          (QWORD, QWORD);
 STDMETHODIMP UtteranceBegin (QWORD);
 STDMETHODIMP UtteranceEnd   (QWORD, QWORD);
 STDMETHODIMP VUMeter        (QWORD, WORD);

protected:
    DWORD    m_dwRefCnt;
 SapiSpeech  *m_pSpchObj;
};


//------------------------------------------------------------------------------
// Description: Dictation Grammar notification sink class definition
//------------------------------------------------------------------------------
class SpchLtdSink : public ISRGramNotifySink
{

public:
    SpchLtdSink( SapiSpeech *pSpch);
    ~SpchLtdSink();

    // IUnkown members that delegate to m_punkOuter
    // Non-delegating object IUnknown
    STDMETHODIMP         QueryInterface (REFIID, LPVOID FAR *);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // ISRNotifySink
 STDMETHODIMP BookMark         (DWORD);
 STDMETHODIMP Paused           ();
 STDMETHODIMP PhraseFinish     (DWORD, QWORD, QWORD, PSRPHRASE, LPUNKNOWN);
 STDMETHODIMP PhraseHypothesis (DWORD, QWORD, QWORD, PSRPHRASE, LPUNKNOWN);
 STDMETHODIMP PhraseStart      (QWORD);
 STDMETHODIMP ReEvaluate       (LPUNKNOWN);
 STDMETHODIMP Training         (DWORD);
 STDMETHODIMP UnArchive        (LPUNKNOWN);

protected:
    DWORD     m_dwRefCnt;
 SapiSpeech   *m_pSpchObj;
private:
};


//------------------------------------------------------------------------------
// Description: Sapi speech engine interface class definition
//------------------------------------------------------------------------------
class SapiSpeech
{
private: // variables
 PISRCENTRAL    m_pSpchCentral;
 PISRGRAMCOMMON   m_pGramCommon;
 PISRGRAMDICTATION  m_pSpchGramDict;
 PISRGRAMCOMMON   m_pLtdGramCommon;
 int      state;

public:  // variables
 CEdit    *m_pCEdit;   // This is where dictated text goes
 CListBox   *m_pStatusLB;
 SpchDctSink   *m_pSpchDctSink;
 SpchLtdSink   *m_pSpchLtdSink;
 SpchEngSink   *m_pSpchEngSink;

private: // methods
 const char *getGrammarLanguageSuffix(GUID &engGuid);
 const char *getStopPhrase(const char *pCountryCode);
 int   initForDictation(int Sequencing);
 int   initGrammars( const char * const stopPhrase );
 void  terminate();

public:  // methods
    SapiSpeech(CEdit *pCEdit);
   ~SapiSpeech();
 int   getState(void) { return state; }
 void  logEventSink(SPCHEVENTID id, char *fmt, ...);
 int   activate(BOOL pause = FALSE);
 int   deactivate();

 void  setDebugCtrl(CListBox *pLB) { m_pStatusLB = pLB; }
    int      resetContext( void );

};


 

 

 

#include "stdafx.h"
#include <winreg.h>
#include <speech.h>
#include "SetIBM.h"
#include "SetDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


#define CTRL_ENGINE_CONNECT_ID        100

extern PISRENUM pISRModeEnum;
extern PIVOICECMD pIVoiceCmd;

/////////////////////////////////////////////////////////////////////////////
// CSetIBMApp

BEGIN_MESSAGE_MAP(CSetIBMApp, CWinApp)
        //{{AFX_MSG_MAP(CSetIBMApp)
                // NOTE - the ClassWizard will add and remove mapping macros here.
                //    DO NOT EDIT what you see in these blocks of generated code!
        //}}AFX_MSG
        ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetIBMApp construction

CSetIBMApp::CSetIBMApp()
{
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
  m_bNoGUI = FALSE;
  m_iExitCode = EXIT_OK;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSetIBMApp object

CSetIBMApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSetIBMApp initialization

BOOL CSetIBMApp::InitInstance()
{
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.

    if ( FAILED(CoInitialize(NULL)) ) return FALSE;

#ifdef _AFXDLL
    Enable3dControls();             // Call this when using MFC in a shared DLL
#else
    Enable3dControlsStatic();       // Call this when linking to MFC statically
#endif

 // Perform our task
 m_iExitCode = DoApplication();

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    CoUninitialize();

    return FALSE;
}

int CSetIBMApp::ExitInstance()
{


 // TODO: Add your specialized code here and/or call the base class
 int rc = CWinApp::ExitInstance();
 
 // return own exit code if not zero
 return (m_iExitCode != 0 ? m_iExitCode : rc);
}

/////////////////////////////////////////////////////////////////////////////
// CSetIBMApp

CSetIBMCommandLineInfo::CSetIBMCommandLineInfo() : CCommandLineInfo()
{
 m_bSwitchF = FALSE;
}

void CSetIBMCommandLineInfo::ParseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
{
 // only process switches
 if (!bFlag) return;

 switch(tolower(lpszParam[0]))
 {
 case 'f':      // switch /f: (F)orce ViaVoice default
  m_bSwitchF = TRUE;
  break;
 }
}

int CSetIBMApp::DoApplication(void)
{
 // Parse command line for parameters.
 CSetIBMCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 if ( cmdInfo.m_bSwitchF )
  m_bNoGUI=TRUE;

 CSetIBMDlg dlg;
 int rc;
   
 if ( !m_bNoGUI )
 {
  m_pMainWnd = &dlg;   // app's main wnd is the dlg
  rc = dlg.DoModal();
 }
 else
  rc = dlg.DoInvisible();  // do not show any window

 switch (rc)
 {
 case IDOK:
  // TODO: Place code here to handle when the dialog is
  //  dismissed with OK
  break;
 case IDCANCEL:
  // TODO: Place code here to handle when the dialog is
  //  dismissed with Cancel
  break;
 case IDABORT:
  //error occured
  return EXIT_LANGNI;
 case IDCLOSE:
  return EXIT_ERR;
 }

 return EXIT_OK;
}

原创粉丝点击