Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SpeechRecognitionConnector

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

A SpeechRecognitionConnector instance can transfer audio data from a SpeechRecognitionEngine instance (in System.Speech) to an AudioVideoFlow instance that is attached to the SpeechRecognitionConnector instance.

The stream of audio data produced by a SpeechRecognitionConnector instance is compatible with SpeechFX, the System.Speech namespace in Microsoft .NET Framework 3.0. One such stream is provided every time Start is called on the SpeechRecognitionConnector. The stream contains the audio up to the point at which Stop is called on the connector. Calling Start again then generates a new stream for the new interval.

Before an application can call the Start method on a SpeechRecognitionConnector instance, a AudioVideoFlow instance must have been previously attached to the connector, and the State of the AudioVideoFlow instance must be Active. If both conditions are not met, Start throws an exception.

To use SpeechRecognitionConnector

  1. Create an instance of this class.

    SpeechRecognitionConnector recoConn = new SpeechRecognitionConnector();
    
    
  2. Attach an AudioVideoFlow instance (assumed to have been previously constructed).

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

    SpeechRecognitionStream recoStream = SpeechRecognitionConnector.Start();
    

    This step alerts the AudioVideoFlow to the existence of the connector and supplies the application with a stream of audio data that begins at roughly the time that Start was called. Start throws 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.

    recoConn.Stop();
    

    The stream remains open-ended (that is, calls to Read past 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.

    recoStream.Dispose();
    

    This will return any buffers remaining in the stream to the SpeechRecognitionConnector connector.

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

    recoConn.Dispose();
    

The SpeechRecognitionConnector class has the following constructor.

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

The following are the public properties on the SpeechRecognitionConnector class.

// 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;}

The following are the public methods on the SpeechRecognitionConnector class.

// 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();

Start throws InvalidOperationException if the SpeechRecognitionConnector is not bound to an AudioVideoFlow instance, or if the SpeechRecognitionConnector is already started.

AttachFlow throws InvalidOperationException if an AudioVideoFlow is already attached, and throws NullArgumentException if its AudioVideoFlow argument is null.

The SpeechRecognitionConnector class has no events.

Show:
© 2015 Microsoft