ISpRecoContext::Pause (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3


ISpRecoContext::Pause pauses the engine object to synchronize with the speech recognition (SR) engine.

The SR engine pauses at its synchronization point to allow grammars and rule states to be changed freely. The engine remains paused until the Resume method is called.

The caller must call ::Resume once for every call that is made to ::Pause.

   DWORD   dwFlags


[in] Reserved, must be zero.

Return values

S_OKFunction completed successfully.
E_INVALIDARGdwFlags is not set to zero.

Remarks (when using ISpMMSysAudio as audio input)

Pausing the SR engine will stop recognition, but input audio will continue to be collected and stored by SAPI in an audio buffer. After the application is done with the state change, it should call ISpRecoContext::Resume. SAPI will automatically feed the buffered audio data into the SR engine, ensuring that no real-time audio data is lost and that the user experience is not interrupted.

However, the SAPI audio buffer has a static limit to prevent large amounts of system memory from being consumed by SAPI applications or SR engines. Therefore, ::Pause should be used by the SR engine for very short periods of time for state changes (e.g., updating grammar, or rule states). Pausing the SR engine will affect all recognition contexts connected to that SR engine including other Speech applications currently running.

If the SR engine is paused too long, and the audio buffer is filled, a buffer overflow will occur. The application can detect this error by setting an event interest in SPEI_END_SR_STREAM (see SPEVENTENUM), and checking the LPARAM of the SPEVENT structure (see CSpEvent::EndStreamResult).

SAPI will automatically attempt to restart the SR Engine's recognition thread after the final ISpRecoContext::Resume has been called. Consequently, the audio data collected between the point when the buffer overflow occurred, and when the stream was reactivated, will be completely lost. This would result in a less than optimal user experience, and have a negative effect on all running speech applications, the SR engine, and SAPI.

The SR engine decides when the call to ::Pause will return based on when it segments the audio stream. The SR Engine segments the audio stream after the utterance is complete, which is decided based on timeout parameters (see Speech Recognition Engine Properties).

In very noisy environments, the SR Engine may have difficulty segmenting the audio stream, resulting in long timeouts. If you are calling ::Pause in response to a user action, you may wish to consider calling ISpRecognizer::SetRecoState ( SPRST_INACTIVE ) or ISpRecognizer::SetRecoState (SPRST_INACTIVE_WITH_PURGE ). Use these calls with caution as they act globally and immediately.

The following code snippet illustrates the use of ::Pause.

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

// Set up the recognition context.
// ...

// Pause the context so that event notifications are not received.
hr = cpRecoContext->Pause(NULL);

if (SUCCEEDED(hr))
   // Quickly perform the processing - see the
   // Remarks section in ISpRecoContext::Pause.
   // ...

   hr = cpRecoContext->Resume(NULL);

// Applications will start receiving event notifications again.
if (SUCCEEDED(hr))
   // Do stuff here.