Specify source language for speech to text

In this article, you'll learn how to specify the source language for an audio input passed to the Speech SDK for speech recognition. Additionally, example code is provided to specify a custom speech model for improved recognition.

How to specify source language in C#

In this example, the source language is provided explicitly as a parameter using SpeechRecognizer construct.

var recognizer = new SpeechRecognizer(speechConfig, "de-DE", audioConfig);

In this example, the source language is provided using SourceLanguageConfig. Then, the sourceLanguageConfig is passed as a parameter to SpeechRecognizer construct.

var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("de-DE");
var recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);

In this example, the source language and custom endpoint are provided using SourceLanguageConfig. Then, the sourceLanguageConfig is passed as a parameter to SpeechRecognizer construct.

var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("de-DE", "The Endpoint ID for your custom model.");
var recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);

Note

SpeechRecognitionLanguage and EndpointId set methods are deprecated from the SpeechConfig class in C#. The use of these methods are discouraged, and shouldn't be used when constructing a SpeechRecognizer.

How to specify source language in C++

In this example, the source language is provided explicitly as a parameter using the FromConfig method.

auto recognizer = SpeechRecognizer::FromConfig(speechConfig, "de-DE", audioConfig);

In this example, the source language is provided using SourceLanguageConfig. Then, the sourceLanguageConfig is passed as a parameter to FromConfig when creating the recognizer.

auto sourceLanguageConfig = SourceLanguageConfig::FromLanguage("de-DE");
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, sourceLanguageConfig, audioConfig);

In this example, the source language and custom endpoint are provided using SourceLanguageConfig. The sourceLanguageConfig is passed as a parameter to FromConfig when creating the recognizer.

auto sourceLanguageConfig = SourceLanguageConfig::FromLanguage("de-DE", "The Endpoint ID for your custom model.");
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, sourceLanguageConfig, audioConfig);

Note

SetSpeechRecognitionLanguage and SetEndpointId are deprecated methods from the SpeechConfig class in C++ and Java. The use of these methods are discouraged, and shouldn't be used when constructing a SpeechRecognizer.

How to specify source language in Java

In this example, the source language is provided explicitly when creating a new SpeechRecognizer.

SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, "de-DE", audioConfig);

In this example, the source language is provided using SourceLanguageConfig. Then, the sourceLanguageConfig is passed as a parameter when creating a new SpeechRecognizer.

SourceLanguageConfig sourceLanguageConfig = SourceLanguageConfig.fromLanguage("de-DE");
SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);

In this example, the source language and custom endpoint are provided using SourceLanguageConfig. Then, the sourceLanguageConfig is passed as a parameter when creating a new SpeechRecognizer.

SourceLanguageConfig sourceLanguageConfig = SourceLanguageConfig.fromLanguage("de-DE", "The Endpoint ID for your custom model.");
SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);

Note

setSpeechRecognitionLanguage and setEndpointId are deprecated methods from the SpeechConfig class in C++ and Java. The use of these methods are discouraged, and shouldn't be used when constructing a SpeechRecognizer.

How to specify source language in Python

The first step is to create a speech_config:

speech_key, service_region = "YourSubscriptionKey", "YourServiceRegion"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

Next, specify the source language of your audio with speech_recognition_language:

speech_config.speech_recognition_language="de-DE"

If you're using a custom model for recognition, you can specify the endpoint with endpoint_id:

speech_config.endpoint_id = "The Endpoint ID for your custom model."

How to specify source language in Javascript

The first step is to create a SpeechConfig:

var speechConfig = sdk.SpeechConfig.fromSubscription("YourSubscriptionkey", "YourRegion");

Next, specify the source language of your audio with speechRecognitionLanguage:

speechConfig.speechRecognitionLanguage = "de-DE";

If you're using a custom model for recognition, you can specify the endpoint with endpointId:

speechConfig.endpointId = "The Endpoint ID for your custom model.";

How to specify source language in Objective-C

The first step is to create a speechConfig:

SPXSpeechConfiguration *speechConfig = [[SPXSpeechConfiguration alloc] initWithSubscription:@"YourSubscriptionkey" region:@"YourRegion"];

Next, specify the source language of your audio with speechRecognitionLanguage:

speechConfig.speechRecognitionLanguage = @"de-DE";

If you're using a custom model for recognition, you can specify the endpoint with endpointId:

speechConfig.endpointId = @"The Endpoint ID for your custom model.";

See also

  • For a list of supported languages and locales for speech to text, see Language support.

Next steps