【问题标题】:How to Create a Simple Dictation Pad in Delphi2009+Vista如何在Delphi2009+Vista中创建一个简单的听写板
【发布时间】:2011-02-14 02:56:18
【问题描述】:

代码没那么复杂..

  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 这样的命令。请帮助.....对不起我的英语

【问题讨论】:

    标签: delphi delphi-2009 speech-recognition sapi


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我尝试将 SpSharedRecoContext 更改为 SpInprocRecoContext 但它不会检测到任何语音信号。有简单的代码吗?
    • 编辑答案更明确。
    • 好的,我明白了...谢谢它解决了问题。非常感谢。更强大!
    【解决方案2】:

    似乎有用的代码是:

    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 呢?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 2021-04-09
      • 2010-09-18
      相关资源
      最近更新 更多