A SpeechRecognitionConnectorinstance can transfer audio data from a SpeechRecognitionEngineinstance (in System.Speech) to an AudioVideoFlowinstance that is attached to the SpeechRecognitionConnectorinstance.

The stream of audio data produced by a SpeechRecognitionConnectorinstance is compatible with SpeechFX, the System.Speechnamespace in Microsoft .NET Framework 3.0. One such stream is provided every time Startis called on the SpeechRecognitionConnector. The stream contains the audio up to the point at which Stopis called on the connector. Calling Startagain then generates a new stream for the new interval.

Before an application can call the Startmethod on a SpeechRecognitionConnectorinstance, a AudioVideoFlowinstance must have been previously attached to the connector, and the Stateof the AudioVideoFlowinstance must be Active. If both conditions are not met, Startthrows an exception.

To use SpeechRecognitionConnector
  1. Create an instance of this class.

    Copy Code
    SpeechRecognitionConnector recoConn = new
    SpeechRecognitionConnector();
    
  2. Attach an AudioVideoFlowinstance (assumed to have been previously constructed).

    Copy Code
    recoConn.AttachFlow(AudioVideoFlow);
    
  3. Start the connector to initiate speech recognition.

    Copy Code
    SpeechRecognitionStream recoStream =
    SpeechRecognitionConnector.Start();
    

    This step alerts the AudioVideoFlowto the existence of the connector and supplies the application with a stream of audio data that begins at roughly the time that Startwas called. Startthrows an exception if another receiving device is already active. The stream that is supplied is of type SpeechRecognitionStream, which inherits from Stream, the type of stream that SpeechFX expects.

  4. When the application is finished with its speech recognition, it calls Stop.

    Copy Code
    recoConn.Stop();
    

    The stream remains open-ended (that is, calls to Readpast the end will block, rather than return “End of Stream”) until the application calls Stop.

  5. The application owns the stream as soon as it is returned by Start, so when it is finished with the stream, it should call Dispose.

    Copy Code
    recoStream.Dispose();
    

    This will return any buffers remaining in the stream to the SpeechRecognitionConnectorconnector.

  6. When the application is completely finished with the connector itself, it should call Disposeto free up all unmanaged buffers.

    Copy Code
    recoConn.Dispose();
    

SpeechRecognitionConnector Constructors

The SpeechRecognitionConnectorclass has the following constructor.

Copy Code
// Creates a new instance of the SpeechRecognitionConnector class.
public SpeechRecognitionConnector();

SpeechRecognitionConnector Properties

The following are the public properties on the SpeechRecognitionConnectorclass.

Copy Code
// Gets whether the SpeechRecognitionConnector is currently
running.
public bool IsActive {get;}

// Gets whether the SpeechRecognitionConnector is currently bound
to an AudioVideoFlow.
public bool IsAttached {get;}

SpeechRecognitionConnector Methods

The following are the public methods on the SpeechRecognitionConnectorclass.

Copy Code
// Begins recording audio into a new stream.
// The caller is responsible for disposing the stream returned by
this method.
public SpeechRecognitionStream Start()

// Places a cap on the current stream, and stops recording audio.
// A stream that is capped has no more data. 
// Does nothing if the SpeechRecognitionConnector is already
stopped.
// Also releases the receiver, so that another device can use the
AudioVideoFlow.
public void Stop()

// Disposes the SpeechRecognitionConnector.
public void Dispose()

// Specifies which AudioVideoFlow will provide audio data for
speech recognition.
// Only one AudioVideoFlow can be attached at a time.
public void AttachFlow(AudioVideoFlow audioVideoFlow)

// Detaches the current AudioVideoFlow, freeing the connector to
use another.
// Does nothing if a flow is not attached.
public void DetachFlow();

Startthrows InvalidOperationExceptionif the SpeechRecognitionConnectoris not bound to an AudioVideoFlowinstance, or if the SpeechRecognitionConnectoris already started.

AttachFlowthrows InvalidOperationExceptionif an AudioVideoFlowis already attached, and throws NullArgumentExceptionif its AudioVideoFlowargument is null.

SpeechRecognitionConnector Events

The SpeechRecognitionConnectorclass has no events.