SourceLanguageRecognizer Class

Definition

Detects the source language from audio stream Added in version 1.17.0

public sealed class SourceLanguageRecognizer : Microsoft.CognitiveServices.Speech.Recognizer
type SourceLanguageRecognizer = class
    inherit Recognizer
Public NotInheritable Class SourceLanguageRecognizer
Inherits Recognizer
Inheritance
SourceLanguageRecognizer

Examples

This example uses the source language recognizer from a microphone and receives events generated by the recognizer.

public async Task SourceLanguageContinuousRecognitionAsync()
{
    // Creates an instance of a speech config with specified subscription key and region.
    // Replace with your own subscription key and service region (e.g., "westus").
    var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
    config.SetProperty(PropertyId.SpeechServiceConnection_ContinuousLanguageIdPriority, "Latency");

    // Creates a source language recognizer from microphone.
    using (var sourceLanguageRecognizer = new SourceLanguageRecognizer(config))
    {
        sourceLanguageRecognizer.Recognized += (s, e) => {
            var result = e.Result;
            Console.WriteLine($"Reason: {result.Reason.ToString()}");
            if (result.Reason == ResultReason.RecognizedSpeech)
            {
                var lidResult = AutoDetectSourceLanguageResult.FromResult(e.Result);
                Console.WriteLine($"RECOGNIZED: Language={lidResult.Language}");
            }
        };

        sourceLanguageRecognizer.Canceled += (s, e) => {
            Console.WriteLine($"\n    Canceled. Reason: {e.Reason.ToString()}, CanceledReason: {e.Reason}");
        };

        sourceLanguageRecognizer.SessionStarted += (s, e) => {
            Console.WriteLine("\n    Session started event.");
        };

        sourceLanguageRecognizer.SessionStopped += (s, e) => {
            Console.WriteLine("\n    Session stopped event.");
        };

        // Starts continuous recognition. 
        // Uses StopContinuousRecognitionAsync() to stop recognition.
        await sourceLanguageRecognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

        do
        {
            Console.WriteLine("Press Enter to stop");
        } while (Console.ReadKey().Key != ConsoleKey.Enter);

        // Stops recognition.
        await sourceLanguageRecognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
    }
}

Remarks

See also: Automatic language detection for speech to text

Constructors

SourceLanguageRecognizer(SpeechConfig, AutoDetectSourceLanguageConfig)

Creates a new instance of SourceLanguageRecognizer that determines the source language from a different languageId modes and priorities.

SourceLanguageRecognizer(SpeechConfig, AutoDetectSourceLanguageConfig, AudioConfig)

Creates a new instance of SourceLanguageRecognizer.

Fields

disposed

disposed is a flag used to indicate if object is disposed.

(Inherited from Recognizer)
gch

GC handle for callbacks for context.

(Inherited from Recognizer)
isDisposing

Indicates whether the object is currently being disposed.

(Inherited from Recognizer)
pointerHandle

Internal for logging.

(Inherited from Recognizer)
recognizerLock

recognizerLock is used to synchronize access to objects member variables from multiple threads

(Inherited from Recognizer)

Properties

AuthorizationToken

Gets or sets authorization token used to communicate with the service.

Note: Your code needs to ensure that the authorization token is valid. Before the authorization token expires, your code needs to refresh it by calling this setter with a new valid token. Otherwise, the recognizer will produce errors during recognition.

OutputFormat

Gets the output format setting.

Properties

The collection of properties and their values defined for this SourceLanguageRecognizer. Note: The property collection is only valid until the recognizer owning this Properties is disposed or finalized.

Methods

Dispose()

Dispose of associated resources.

(Inherited from Recognizer)
Dispose(Boolean)

This method performs cleanup of resources. The Boolean parameter disposing indicates whether the method is called from Dispose() (if disposing is true) or from the finalizer (if disposing is false). Derived classes should override this method to dispose resource if needed.

(Inherited from Recognizer)
Finalize()
RecognizeOnceAsync()

Starts source language recognition as an asynchronous operation.

StartContinuousRecognitionAsync()

Starts source language recognition on a continuous audio stream, until StopContinuousRecognitionAsync() is called. You must subscribe to events to receive recognition results.

StopContinuousRecognitionAsync()

Stops a running recognition operation as soon as possible and immediately requests a result based on the the input that has been processed so far. This works for all recognition operations, not just continuous ones, and facilitates the use of push-to-talk or "finish now" buttons for manual audio endpointing.

Events

Canceled

The event Canceled signals that the speech to source language recognition was canceled.

Recognized

The event Recognized signals that a final recognition result is received.

SessionStarted

Defines event handler for session started event.

(Inherited from Recognizer)
SessionStopped

Defines event handler for session stopped event.

(Inherited from Recognizer)
SpeechEndDetected

Defines event handler for speech end detected event.

(Inherited from Recognizer)
SpeechStartDetected

Defines event handler for speech start detected event.

(Inherited from Recognizer)

Applies to