Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpRecoContext::Pause

ISpRecoContext::Pause pauses the speech recognition (SR) engine object to synchronize with the 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 ISpRecoContext::Resume method is called.

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

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT Pause(</strong> <strong> DWORD</strong> <em>dwFlags</em> <strong>);</strong> </pre>

Parameters

  • dwFlags
    [in] Reserved, must be zero.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG dwFlags is not set to zero.

Remarks (when using ISpMMSysAudio as audio input)

Pausing the speech recognition (SR) engine will stop recognition, but input audio will continue to be collected and stored by the Speech Platform in an audio buffer. After the application is done with the state change, it should call ISpRecoContext::Resume. The Speech Platform 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 Speech Platform's audio buffer has a static limit to prevent large amounts of system memory from being consumed by Speech Platform applications or SR engines. Therefore, ::Pause should be used by the SR engine for very short periods of time for state changes (for example, updating the states of grammars or rules). Pausing the SR engine will affect all recognition contexts connected to that SR engine.

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).

The Speech Platform 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 may result in a poor user experience, and have a negative effect on the speech application, the SR engine, and the Speech Platform.

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 Modify 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. // ...

hr = cpRecoContext->Resume(NULL); }

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

`