Share via


SpeechRecoContext SetAdaptationData Method (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecoContext

SetAdaptationData Method

The SetAdaptationData method passes the speech recognition (SR) engine a string of adaptation data.

An application can improve recognition accuracy for dictating uncommon words, or uncommon word groupings by training the SR engine for the new words or word groupings. An application creates or obtains typical text and sends the results to the engine using the SetAdaptationData method.

  
    SpeechRecoContext.SetAdaptationData(
     AdaptationString As String
)

Parameters

  • AdaptationString
    Specifies the AdaptationString.

Return Value

None.

Remarks

Applications using adaptation data should break the data into small sections (1KB or less) and submit the sections individually. First, specify interest in adaptation events using the ISpeechRecoContext.EventInterests method. The Adaptation event interest is on by default. Then, send a small data section to the SR engine using the SetAdaptationData method, and wait for an ISpeechRecoContext.Adaptation event, which indicates that the adaptation data has been processed. Send all successive data sections in this way. Finally, use the EventInterests method to turn off Adaptation events. Since this event is returned only after an explicit SetAdaptationData call, the event interest does not need to be removed unless an excessive number of words is added and the processing time becomes unacceptable. The Adaptation event indicates that the engine has processed the AdaptationString and that it is ready to accept another SetAdaptationData call.

Example

The following Visual Basic form code demonstrates adding an uncommon word, which raises the recognition context's Adaptation event. To run this code, paste it into the Declarations section of a form that contains no controls.

  
Option Explicit

Public WithEvents RecoContext As SpSharedRecoContext

Private Sub Form_Load()

    Dim Grammar As ISpeechRecoGrammar
    Dim Recognizer As SpSharedRecognizer

    On Error GoTo EH

    ' Set up speech recognition and grammar:
    Set Recognizer = New SpSharedRecognizer
    Set RecoContext = Recognizer.CreateRecoContext
    Set Grammar = RecoContext.CreateGrammar(1)
    Grammar.DictationLoad
    Grammar.DictationSetState SGDSActive

    ' Raise Adaptation event.
    RecoContext.SetAdaptationData "Simmiting"

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub RecoContext_Adaptation _
   (ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant)

    MsgBox "Adaptation data/word(s) just added.", vbInformation
    End

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