ISpRecoContext::GetVoice

This method gets a reference to the voice associated with the speech recognition context.

HRESULT GetVoice(
  ISpVoice** ppVoice
);

Parameters

  • ppVoice
    [out] Address of a pointer to an object implementing ISpVoice. The caller must call IUnknown::Release when finished with this object.

Return Values

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_POINTER Invalid pointer.
FAILED(hr) Appropriate error message.

Remarks

If an application previously called ISpRecoContext::SetVoice on the same ISpRecoContext object, then the Voice interface retrieved from GetVoice will match that of the SetVoice call. Release must still call the ISpVoice reference for each GetVoice call, even though the interface pointer is the same.

The ISpVoice output format will be the same format as the associated SR engine's audio input format (see ISpRecognizer and ISpSREngine::GetInputAudioFormat). Using the same audio format for input and output source is useful for sound cards that do not support full-duplex audio (such as input format must match output format). If the input format quality is lower than the output format quality, the output format quality will be down-sampled to the lower quality.

Applications implementing a "barge-in" type functionality will need to tie the Voice object to the Speech Recognition object. Applications can also use this method (see ISpRecoContext::SetVoicePurgeEvent).

Example

The following code snippet illustrates the use of this method and "barge-in" setup

HRESULT hr = S_OK;
// create a shared recognition context
hr = cpRecoContext.CoCreateInstance(CLSID_SpSharedRecoContext);
// Check hr
// create a voice from the context (with same audio format as context)
hr = cpRecoContext->GetVoice(&cpVoice);
// Check hr
// tell the associated Voice to stop speaking when the SR Engine hears a
recognizable sound
hr = cpRecoContext->SetVoicePurgeEvent(SPFEI(SPEI_SOUND_START));
// Check hr

Requirements

OS Versions: Windows CE .NET 4.1 and later.
Header: Sapi.h, Sapi.idl.
Link Library: Sapilib.lib.

See Also

ISpRecoContext | SAPI Interfaces

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.