Partager via


ISpRecognizer::GetInputObjectToken (SAPI 5.4)

Microsoft Speech API 5.4

ISpRecognizer::GetInputObjectToken

ISpRecognizer::GetInputObjectToken retrieves the input token object for the stream currently being used.

GetInputObjectToken will always return the default audio input object token when using a shared recognizer.  

  
    HRESULT GetInputObjectToken(ISpObjectToken   **ppToken
);

Parameters

  • ppToken
    [out] Gets filled in with the current input object token pointer.

Return values

Value
S_OK
S_FALSE
E_POINTER
SPERR_UNINITIALIZED
FAILED(hr)

Remarks

Applications will not normally need to use this method, but it can be used to find out specific details of the object token that was used to create the audio input stream.

If an application receives feedback from the SR engine that recognition quality is low, (e.g., poor audio signal quality (see SPEI_INTERFERENCE, or that the microphone needs adjustment (see SPEI_REQUEST_UI for SPDUI_MicTraining), etc.), it may be helpful to reconfigure the audio input settings. SAPI defines two specific types of audio UI that an audio object token can provide: volume (SPDUI_AudioVolume) and properties (SPDUI_AudioProperties). An application can use ::GetInputObjectToken, ISpObjectToken::IsUISupported, and ISpObjectToken::DisplayUI to display audio UI in an effort to improve speech recognition.

Example

The following code snippet illustrates the use of ISpRecognizer::GetInputObjectToken when displaying audio UI.

  
// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpRecognizer>       cpRecognizer;
CComPtr<ISpTokenUI>          cpTokenUI;
CComPtr<ISpObjectToken>      cpObjectToken;
BOOL                         fSupported;
const WCHAR                  *MY_AUDIO_DIALOG_TITLE = L"Foo Caption";
HWND                         hwndParent;

// Check if the current recognizer has an object token.
hr = cpRecognizer->GetInputObjectToken(&cpObjectToken;);

if (SUCCEEDED(hr))
{
   // Get the object token's UI.
   hr = cpObjectToken->QueryInterface(&cpTokenUI;);
}

if (SUCCEEDED(hr))
{
   // Check if default audio input object has UI for volume.
   hr = cpTokenUI->IsUISupported(SPDUI_AudioVolume, NULL, NULL, NULL, &fSupported;);
}

if (SUCCEEDED(hr))
{
   // If fSupported == TRUE, then default audio input object has UI for Volume.

   // Display the default audio input object's Volume UI (you need
   // to have handle for hwndParent before executing next statement).
   hr = cpTokenUI->DisplayUI(hwndParent, MY_AUDIO_DIALOG_TITLE, SPDUI_AudioVolume, NULL, NULL, cpObjectToken, NULL);
}

if (SUCCEEDED(hr))
{
   // Do stuff here.
}