ISpRecoContext::GetStatus

Microsoft Speech SDK

The Microsoft.com Speech website Microsoft Speech SDK SAPI 5.1

ISpRecoContext::GetStatus

ISpRecoContext::GetStatus retrieves current state information associated with a context (e.g., last SR engine requested UI, audio signal status, etc.).

HRESULT GetStatus(
   SPRECOCONTEXTSTATUS   *pStatus
);

Parameters

pStatus
[out] Address of the SPRECOCONTEXTSTATUS structure that receives the context state information.

Return values

Value Description
S_OK Function completed successfully.
E_POINTER pStatus is invalid or bad.
FAILED (hr) Appropriate error message.

Remarks

A graphical application that is interested in SPEI_REQUEST_UI events from the SR engine can call ISpRecoContext::GetStatus, and check the szRequestTypeOfUI field to check the last requested UI-type. After the application has called ISpRecognizer::DisplayUI, the SR engine can clear the szRequestTypeOfUI field by calling ISpSREngineSite::AddEvent with a NULL UI-type.

An application can also periodically query the recognition context status to check the audio signal quality (see also SPINTERFERENCE) and respond appropriately. An application can prompt the user to access the SR engine's microphone training UI to improve the audio signal quality (see SPDUI_MicTraining), or prompt the user to modify the audio settings using Speech properties in Control Panel (see SPDUI_AudioProperties and SPDUI_AudioVolume).

Example

The following code snippet illustrates the use of ISpRecoContext::GetStatus for responding to SR engine UI requests.

    HRESULT hr = S_OK;

    // assume UI request [SPEI_REQUEST_UI] has been received

    // check what kind of UI the SR Engine wants
    hr = cpRecoContext->GetStatus(&contextStatus);
    // Check hr

    // get a reference to the SR Engine
    hr = cpRecoContext->GetRecognizer(&cpRecognizer);
    // Check hr

    // sanity check that the UI type is supported
    hr = cpRecognizer->IsUISupported(contextStatus.szRequestTypeOfUI, NULL, NULL, &fSupported);
    // Check hr

    // ask the SR engine to display the UI, and use the default window title
    hr = cpRecognizer->DisplayUI(MY_HWND, NULL, contextStatus.szRequestTypeOfUI, NULL, NULL);
    // Check hr