ISpRecoContext::GetVoice
ISpRecoContext::GetVoice retrieves a reference to an ISpVoice object that is associated with the ISpRecoContext object.
HRESULT GetVoice(
ISpVoice **ppVoice
);
Parameters
- ppVoice
- [in] Address of the ISpVoice interface. IUnknown::Release must be called on the ISpVoice interface when finished.
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, 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).
Related Samples
The CoffeeS3 Sample application uses ISpRecoContext::GetVoice and the "barge-in" functionality.
Example
The following code snippet illustrates the use of ISpRecoContext::GetVoice 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