2010-04-30 5 views
1

le code ne sont pas si complecated ..Comment créer un Pad simple dans Dictation 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; 

Mon problème, est la commande vocale vista-OS interceptera sur mon programme. Si je dis "START", au lieu d'écrire commencer sur memo1, appuyez sur le menu Démarrer sur mon bureau. ou quoi que ce soit de commander comme START CANCEL EDIT DELETE SELECT etc. s'il vous plaît aider ..... désolé pour mon anglais

Répondre

2

Vous devez utiliser un système de reconnaissance de processus, plutôt que le système de reconnaissance partagé. Regardez l'objet SpInprocRecoContext.

En particulier, vous devez également définir la propriété AudioInput du programme de reconnaissance, de sorte que le programme de reconnaissance inproc sache d'où tirer l'audio.

Un exemple complet de dictée simple fait partie du SDK Windows 7 ou Windows Vista - après l'avoir installé, il se trouve dans $ (WindowsSdkDir) \ Samples \ winui \ speech \ simpledictation.

Les exemples sont en C++, mais vous devriez pouvoir l'utiliser comme point de lancement.

+0

J'ai essayé de changer SpSharedRecoContext en SpInprocRecoContext mais il ne détectera aucun signal vocal. avez-vous un code simple? – XBasic3000

+0

La réponse éditée est plus explicite. –

+0

Ok, je vois ... Thanx Cela résout le problème. Merci beaucoup. plus de pouvoir! – XBasic3000

1

Il semblerait que le bit de code est utile:

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

Mais comment pourrions-nous traduire en Delphi?

Questions connexes