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我呀!!!
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我呀!!!
看来是个发音的程序;
哪个SETSTATE就不用说了吧,就是设置一个类的BOOLEAN;后面是两个按钮;失效或有效;
第一个也没多少;就是哪个ISpeechRecoResult?可哪里去找;
'=============================================================================
' 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
PROJECT---IMPORT TYPE LIBRAY;
找到MS SPEECH OBJECT LIBRAY[5。1];
然后INSTALL;
要发音;只要用SPVOCIE。
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;
我在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;
报错,说少参数?请赐教!
[StartElement As Long = 0],
[Elements As Long = -1],
[UseReplacements As Boolean = True]
) As String
楼上的高手请赐教呀:)
strText := Result.PhraseInfo.GetText(EmptyParam,EmptyParam,EmptyParam)
在USES中不能加入Variant。且报错:
Project Project1.exe raised exception class EVariantError with message'无效的变量类型转换'.Process stopped.Use Step or Run to continue.
请赐教!多谢
在USES中不能加入Variant。且报错:
Project Project1.exe raised exception class EVariantError with message'无效的变量类型转换'.Process stopped.Use Step or Run to continue.
请赐教!多谢