ISpRecoContext::GetVoice (SAPI 5.4)

Speech API 5.4
Microsoft Speech API 5.4


ISpRecoContext::GetVoice retrieves a reference to an ISpVoice object that is associated with the ISpRecoContext object.

   ISpVoice   **ppVoice


[in] Address of the ISpVoice interface. IUnknown::Release must be called on the ISpVoice interface when finished.

Return values

S_OKFunction completed successfully.
E_POINTERInvalid pointer.
FAILED(hr)Appropriate error message.


If an application previously called ISpRecoContext::SetVoice on the same ISpRecoContext object, 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 output format of the ISpVoice will be the same format as the associated audio input format of the SR engine (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 (i.e., 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 SR object. Applications can also use ISpRecoContext::GetVoice (see ISpRecoContext::SetVoicePurgeEvent).


The following code snippet illustrates the use of ISpRecoContext::GetVoice and "barge-in" setup

// Declare local identifiers:
HRESULT	                   hr = S_OK;
CComPtr<ISpRecoContext>    cpRecoContext;
CComPtr<ISpVoice>          cpVoice;

// Create a shared recognition context.
hr = cpRecoContext.CoCreateInstance(CLSID_SpSharedRecoContext);

if (SUCCEEDED(hr))
   // Create a voice from the context (with
   // same audio format as context)
   hr = cpRecoContext->GetVoice(&cpVoice;);

if (SUCCEEDED(hr))
   // Tell the associated Voice to stop speaking when
   // the SR Engine hears a recognizable sound.
   hr = cpRecoContext->SetVoicePurgeEvent(SPFEI(SPEI_SOUND_START));

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