Interface: ISpeechRecoResult
Times Property
The Times property retrieves the time information associated with the result.
Syntax
Set: | (This property is read-only) |
Get: | ISpeechRecoResultTimes = ISpeechRecoResult.Times |
Parts
- ISpeechRecoResult
- The owning object.
- ISpeechRecoResultTimes
-
Set: (This property is read-only)
Get: An ISpeechRecoResultTimes variable containing the time information for the recognition.
Example
The following Visual Basic form code reads ISpeechRecoResultTimes for the current recognition. Because that object's four properties are read-only, their values are added to a string for display in a message box. RecoResult.
To run this code, paste it into the Declarations section of a form that contains no controls. In addition to the usual reference to the Microsoft Speech Object Library, this code also needs a reference to the simpleaudio 1.0 Type Library.
Option Explicit
Const AUDIOFORMAT = SAFT8kHz16BitMono
' Text-to-Speech variables:
Dim WithEvents Voice As SpVoice
Dim EndofStream As Boolean
Dim AudioPlugOut As SpAudioPlug
' Speech Recognition variables:
Dim WithEvents RecoContext As SpInProcRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim Recognizer As SpInprocRecognizer
Dim AudioPlugIn As SpAudioPlug
Private Sub Form_Load()
Const Text = "One of the world's seven wonders"
Dim Output As Variant
On Error GoTo EH
Set Voice = New SpVoice
' Set up output audio:
Set AudioPlugOut = New SpAudioPlug
AudioPlugOut.Init True, AUDIOFORMAT
Set Voice.AudioOutputStream = AudioPlugOut
' Set up input audio:
Set AudioPlugIn = New SpAudioPlug
AudioPlugIn.Init False, AUDIOFORMAT
Set Recognizer = New SpInprocRecognizer
Set Recognizer.AudioInputStream = AudioPlugIn
' Set up speech recognition and explicitly set
' flag to retain audio portion of recognition
' (default behavior is not to retain):
Set RecoContext = Recognizer.CreateRecoContext
RecoContext.RetainedAudio = SRAORetainAudio
Set Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad
Grammar.DictationSetState SGDSActive
' Speak some text to be recognized.
Voice.Speak Text, SVSFlagsAsync
Do While EndofStream = False
DoEvents
' Get audio data from audio object.
Output = AudioPlugOut.GetData
' Output audio data to input audio object--
If (Len(Output) * 2 <> 0) Then
AudioPlugIn.SetData (Output)
End If
Loop
Grammar.DictationSetState SGDSInactive
EH:
If Err.Number Then ShowErrMsg
End Sub
Private Sub RecoContext_Recognition _
(ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant, _
ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
ByVal Result As SpeechLib.ISpeechRecoResult)
Const NL = vbNewLine
Dim myTimes As ISpeechRecoResultTimes
Dim T As String
On Error GoTo EH
Set myTimes = Result.Times()
With myTimes
T = "Len: " & .Length & NL
T = T & "Start: " & .OffsetFromStart & NL
T = T & "Time: " & .StreamTime & NL
T = T & "TickCount: " & .TickCount
MsgBox T, vbInformation
End
End With
EH:
If Err.Number Then ShowErrMsg
End Sub
Private Sub Voice_EndStream _
(ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant)
EndofStream = True
End Sub
Private Sub ShowErrMsg()
' Declare identifiers:
Dim T As String
T = "Desc: " & Err.Description & vbNewLine
T = T & "Err #: " & Err.Number
MsgBox T, vbExclamation, "Run-Time Error"
End
End Sub