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:Integer;
                                                                StreamPosition:OleVariant;
                                                                RecognitionType:SpeechRecognitionType;
                                                                const Result:ISpeechRecoResult);    
始める    
  Memo1.Text:= Result.PhraseInfo.GetText(0、-1、true);    
終わり;    

プロシージャTForm1.SpSharedRecoContext1Hypothesis(ASender:TObject; StreamNumber:Integer;
                                                               StreamPosition:OleVariant;
                                                               const Result:ISpeechRecoResult);    
始める    
  Memo1.Text:= Result.PhraseInfo.GetText(0、-1、true);    
終わり;  

私の問題は、vista-OS音声コマンドが私のプログラムを傍受することでした。「START」と言うと、memo1にstartと書く代わりに、デスクトップのスタートメニューを押します。またはSTARTCANCELEDITDELETESELECTなどのコマンドは助けてください.....私の英語でごめんなさい

4

2 に答える 2

2

共有認識エンジンではなく、インプロセス認識エンジンを使用する必要があります。SpInprocRecoContext オブジェクトを見てください。

特に、インプロセス認識エンジンがオーディオの取得元を認識できるように、認識エンジンの AudioInput プロパティも設定する必要があります。

単純なディクテーションの完全に機能する例は、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 に答える