1

代码没有那么复杂..

  private
{ Private declarations }
SpSharedRecoContext1 : TSpSharedRecoContext;
fMyGrammar : ISpeechRecoGrammar;
procedure SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer;
                                                            StreamPosition: OleVariant;
                                                            RecognitionType: SpeechRecognitionType;
                                                            const Result: ISpeechRecoResult);
procedure SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer;
                                                           StreamPosition: OleVariant;
                                                           const Result: ISpeechRecoResult);
过程 TForm1.FormCreate(Sender: TObject);    
开始    
  SpSharedRecoContext1 := TSpSharedRecoContext.Create(self);    
  SpSharedRecoContext1.OnHypothesis := SpSharedRecoContext1Hypothesis;    
  SpSharedRecoContext1.OnRecognition :=SpSharedRecoContext1Recognition;    
  fMyGrammar := SpSharedRecoContext1.CreateGrammar(0);    
  fMyGrammar.DictationSetState(SGDSActive);    
结尾;    

过程 TForm1.SpSharedRecoContext1Recognition(ASender:TObject;StreamNumber:整数;
                                                                流位置:OleVariant;
                                                                识别类型:语音识别类型;
                                                                常量结果:ISpeechRecoResult);    
开始    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
结尾;    

过程 TForm1.SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer;
                                                               流位置:OleVariant;
                                                               常量结果:ISpeechRecoResult);    
开始    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
结尾;  

我的问题是 vista-OS 语音命令会拦截我的程序。如果我说“开始”,而不是在 memo1 上写开始,它按我桌面上的开始菜单。或者像 START CANCEL EDIT DELETE SELECT 之类的命令。请帮助.....对不起我的英语

4

2 回答 2

2

您需要使用进程内识别器,而不是共享识别器。查看 SpInprocRecoContext 对象。

特别是,您还需要设置识别器的 AudioInput 属性,以便 inproc 识别器知道从哪里获取音频。

一个完整的简单听写示例是 Windows 7 或 Windows Vista SDK 的一部分 - 安装后,它位于 $(WindowsSdkDir)\Samples\winui\speech\simpledictation 中。

这些示例使用 C++,但您应该能够将其用作启动点。

于 2010-04-30T22:43:54.963 回答
1

看起来有用的代码是:

HRESULT hr = S_OK;
CComPtr<ISpRecognizer> cpRecoEngine;
hr = cpRecoEngine.CoCreateInstance(CLSID_SpInprocRecognizer);

if( SUCCEEDED( hr ) )
{
    hr = cpRecoEngine->CreateRecoContext( &m_cpRecoCtxt );
}


// Set recognition notification for dictation
if (SUCCEEDED(hr))
{
    hr = m_cpRecoCtxt->SetNotifyWindowMessage( hDlg, WM_RECOEVENT, 0, 0 );
}


if (SUCCEEDED(hr))
{
    // This specifies which of the recognition events are going to trigger notifications.
    // Here, all we are interested in is the beginning and ends of sounds, as well as
    // when the engine has recognized something
    const ULONGLONG ullInterest = SPFEI(SPEI_RECOGNITION);
    m_cpRecoCtxt->SetInterest(ullInterest, ullInterest);
}

// create default audio object
CComPtr<ISpAudio> cpAudio;
SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &cpAudio);

// set the input for the engine
cpRecoEngine->SetInput(cpAudio, TRUE);
hr = cpRecoEngine->SetRecoState( SPRST_ACTIVE );

但是我们如何将它翻译成 Delphi 呢?

于 2012-06-05T12:00:59.250 回答