Click or drag to resize
SpeechClient Class
ISpeechClient implementation to perform speech recognition.
Inheritance Hierarchy
SystemObject
  Microsoft.Bing.SpeechSpeechClient

Namespace:  Microsoft.Bing.Speech
Assembly:  Microsoft.Bing.Speech (in Microsoft.Bing.Speech.dll) Version: 2.0.1.0 (2.0.1)
Syntax
public sealed class SpeechClient : ISpeechClient, 
	IDisposable

The SpeechClient type exposes the following members.

Constructors
  NameDescription
Public methodSpeechClient
Initializes a new instance of the SpeechClient class used to perform speech recognition with audio data.
Top
Methods
  NameDescription
Public methodDispose
Dispose and clean up resources.
Public methodCode exampleRecognizeAsync
Streams audio asynchronously to the speech service for recognition.
Public methodSubscribeToT
Subscribes the specific event to perform given a action.
Public methodSubscribeToPartialResult
Subscribes to partial speech results.
Public methodSubscribeToRecognitionResult
Subscribes to speech recognition results.
Top
Remarks
Use this client to send audio (for example from a file or any audio source) to the speech service and receive the recognition results.
Examples
var preferences = new Preferences("en-us", new Uri(@"wss://speech.platform.bing.com/api/service/recognition"), new AuthorizationProvider("******************"));

using (var speechClient = new SpeechClient(preferences))
{
    speechClient.SubscribeToPartialResult(
        result =>
            {
                Console.WriteLine(result.DisplayText);
                return Task.FromResult(true);
            });

    speechClient.SubscribeToRecognitionResult(
        result =>
            {
                Console.WriteLine(result.RecognitionStatus);
                return Task.FromResult(true);
            });

    // create an audio content and pass it a stream.
    using (var audio = new FileStream("sample.wav", FileMode.Open, FileAccess.Read))
    {
        var deviceMetadata = new DeviceMetadata(DeviceType.Near, DeviceFamily.Desktop, NetworkType.Ethernet, OsName.Windows, "1607", "Dell", "T3600");
        var applicationMetadata = new ApplicationMetadata("SampleApp", "1.0.0");
        var requestMetadata = new RequestMetadata(Guid.NewGuid(), deviceMetadata, applicationMetadata, "SampleService");

        await speechClient.RecognizeAsync(new SpeechInput(audio, requestMetadata), CancellationToken.None).ConfigureAwait(false);
    }
}
See Also