Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, 
                                    ByVal StreamPosition As Variant,
                                    ByVal RecognitionType As    SpeechRecognitionType,  ByVal Result As ISpeechRecoResult
                                    )
    Dim strText As String
    strText = Result.PhraseInfo.GetText
    Debug.Print "Recognition: " & strText & ", " & _
        StreamNumber & ", " & StreamPosition
    
    ' Append the new text to the text box, and add a space at the end of the
    ' text so that it looks better
    txtSpeech.SelStart = m_cChars
    txtSpeech.SelText = strText & " "
    m_cChars = m_cChars + 1 + Len(strText)
End Sub' This function handles the state of Start and Stop buttons according to
' whether dictation is running.
Private Sub SetState(ByVal bNewState As Boolean)
    m_bRecoRunning = bNewState
    btnStart.Enabled = Not m_bRecoRunning
    btnStop.Enabled = m_bRecoRunning
End Sub人命关天呀,兄弟们99我呀!!!

解决方案 »

  1.   

    脱离了你原来VB的程序,怎么转啊;
    看来是个发音的程序;
    哪个SETSTATE就不用说了吧,就是设置一个类的BOOLEAN;后面是两个按钮;失效或有效;
    第一个也没多少;就是哪个ISpeechRecoResult?可哪里去找;
      

  2.   

    这是完整的例子,楼上的红星在哥请帮帮在下呀!!万分感谢!!!!!!!!!!!!!!!!
     '=============================================================================
    ' This sample demonstrates how to do simple dictation in VB with SAPI 5.1.
    '
    ' It uses shared reco context object, uses the default audio input, loads in
    ' dictation grammar, sets up event handlers, and shows the recognized text in
    ' the dialog text box.
    '
    ' Note: since the text box is using system locale, it may not correctly show
    ' characters in other languages. For example, if you use Chinese Speech
    ' Recognition engine as the default engine on your English OS, the text box
    ' may show garbage even though the engine recognizes Chinese.
    '
    ' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
    '
    '=============================================================================Option ExplicitDim WithEvents RecoContext As SpSharedRecoContext
    Dim Grammar As ISpeechRecoGrammarDim m_bRecoRunning As Boolean
    Dim m_cChars As Integer
    Private Sub Form_Load()
        SetState False
        m_cChars = 0
    End SubPrivate Sub btnStart_Click()
        Debug.Assert Not m_bRecoRunning
        
        ' Initialize recognition context object and grammar object, then
        ' start dictation
        If (RecoContext Is Nothing) Then
            Debug.Print "Initializing SAPI reco context object..."
            Set RecoContext = New SpSharedRecoContext
            Set Grammar = RecoContext.CreateGrammar(1)
            Grammar.DictationLoad
        End If
        
        Grammar.DictationSetState SGDSActive
        SetState True
    End SubPrivate Sub btnStop_Click()
        Debug.Assert m_bRecoRunning
        Grammar.DictationSetState SGDSInactive
        SetState False
    End Sub' This function handles Recognition event from the reco context object.
    ' Recognition event is fired when the speech recognition engines recognizes
    ' a sequences of words.
    Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
                                        ByVal StreamPosition As Variant, _
                                        ByVal RecognitionType As SpeechRecognitionType, _
                                        ByVal Result As ISpeechRecoResult _
                                        )
        Dim strText As String
        strText = Result.PhraseInfo.GetText
        Debug.Print "Recognition: " & strText & ", " & _
            StreamNumber & ", " & StreamPosition
        
        ' Append the new text to the text box, and add a space at the end of the
        ' text so that it looks better
        txtSpeech.SelStart = m_cChars
        txtSpeech.SelText = strText & " "
        m_cChars = m_cChars + 1 + Len(strText)
    End Sub' This function handles the state of Start and Stop buttons according to
    ' whether dictation is running.
    Private Sub SetState(ByVal bNewState As Boolean)
        m_bRecoRunning = bNewState
        btnStart.Enabled = Not m_bRecoRunning
        btnStop.Enabled = m_bRecoRunning
    End Sub
      

  3.   

    我知道转换成DELPHI格式需要花时间,但在下迫切需要这份转换后的代码,请相助!!!!!!!!!
      

  4.   

    也许你需要这么做;
    PROJECT---IMPORT TYPE LIBRAY;
    找到MS SPEECH OBJECT LIBRAY[5。1];
    然后INSTALL;
    要发音;只要用SPVOCIE。
      

  5.   

    文本朗读的我已经会了,这是语音识别例程,请outer2000(天外流星) 大哥帮我!!多谢多谢多谢
      

  6.   

    procedure RecoContext_Recognition(StreamNumber:LongInt;StreamPosition:Variant;RecognitionType:SpeechRecognitionType;Result:ISpeechRecoResult);
    var
      strText:string;
    {m_cChars:Integer;}
    begin
      strText := Result.PhraseInfo.GetText;
      ShowMessage('Recognition: ' + strText + ',' +
        IntToStr(StreamNumber) + ',' + VarToStr(StreamPosition);
        // Append the new text to the text box, and add a space at the end of the
        // text so that it looks better
      txtSpeech.SelStart := m_cChars;
      txtSpeech.SelText := strText + ' ';
      m_cChars := m_cChars+ 1 + Length(strText);
    end;
    // This function handles the state of Start and Stop buttons according to
    // whether dictation is running.
    procedure SetState(bNewState:Boolean);
    {var
      m_bRecoRunning:Boolean;}
    begin
      m_bRecoRunning := bNewState;
      btnStart.Enabled := not m_bRecoRunning;
      btnStop.Enabled := m_bRecoRunning;
    end;
      

  7.   


    我在msdn中找不到定义的类型SpeechRecognitionType(是不是枚举类型?),有返回值的应为函数方法,当函数结束时,给Result赋值。
    function RecoContext_Recognition(var StreamNumber : Int ,
                                        var StreamPosition : Variant,
                                        var RecognitionType : SpeechRecognitionType
                                        ): ISpeechRecoResult
    var
      strText :String;
    begin    strText := Result.PhraseInfo.GetText;
        MessageBox( 'Recognition: ' + strText + ', ' + StreamNumber + ', ' + StreamPosition ,MS_OK);    txtSpeech.SelStart := m_cChars;
        txtSpeech.SelText = strText +' ';
        m_cChars := m_cChars + 1 + Len(strText);
    end;' This function handles the state of Start and Stop buttons according to
    ' whether dictation is running.
    procedure SetState(var bNewState :Boolean)begin
        m_bRecoRunning := bNewState// m_bRecoRunning是在哪里定义的?所以我没办法写
        btnStart.Enabled := not(m_bRecoRunning);
        btnStop.Enabled := m_bRecoRunning;
    end;
      

  8.   

    strText := Result.PhraseInfo.GetText;
    报错,说少参数?请赐教!
      

  9.   

    strText := Result.PhraseInfo.GetText(   //打个括号看看需要什么参数
      

  10.   

    ISpeechPhraseInfo.GetText(
         [StartElement As Long = 0],
         [Elements As Long = -1],
         [UseReplacements As Boolean = True]
    ) As String
      

  11.   

    strText := Result.PhraseInfo.GetText(0,-1,true)后出错:(
    楼上的高手请赐教呀:)
      

  12.   

    试试:
    strText := Result.PhraseInfo.GetText(EmptyParam,EmptyParam,EmptyParam)
      

  13.   

    谢谢楼上“花”的帮助,谢谢!
    在USES中不能加入Variant。且报错:
    Project Project1.exe raised exception class EVariantError with message'无效的变量类型转换'.Process stopped.Use Step or Run to continue.
    请赐教!多谢
      

  14.   

    谢谢楼上cjc861(老七)的帮助 !
    在USES中不能加入Variant。且报错:
    Project Project1.exe raised exception class EVariantError with message'无效的变量类型转换'.Process stopped.Use Step or Run to continue.
    请赐教!多谢