如何在Delphi2009 + Vista中创建简单的听写板

代码没有那么复杂..

  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);
procedure TForm1.FormCreate(Sender: TObject);    
begin    
  SpSharedRecoContext1 := TSpSharedRecoContext.Create(self);    
  SpSharedRecoContext1.OnHypothesis := SpSharedRecoContext1Hypothesis;    
  SpSharedRecoContext1.OnRecognition :=SpSharedRecoContext1Recognition;    
  fMyGrammar := SpSharedRecoContext1.CreateGrammar(0);    
  fMyGrammar.DictationSetState(SGDSActive);    
end;    

procedure TForm1.SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer;
                                                                StreamPosition: OleVariant;
                                                                RecognitionType: SpeechRecognitionType;
                                                                const Result: ISpeechRecoResult);    
begin    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
end;    

procedure TForm1.SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer;
                                                               StreamPosition: OleVariant;
                                                               const Result: ISpeechRecoResult);    
begin    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
end;  

我的问题是,vista-OS语音命令会拦截我的程序。 如果我说“开始”,而不是写在memo1上的开始,它按下我的桌面上的开始菜单。 或什么命令像开始取消编辑删除选择等请帮助.....抱歉我的英语


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

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

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

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


看起来有用的代码是:

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 );

但是,我们如何将其转化为德尔福?

链接地址: http://www.djcxy.com/p/91085.html

上一篇: How to Create a Simple Dictation Pad in Delphi2009+Vista

下一篇: How to stop parsing xml document with SAX at any time?