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 the following example, the source language is provided explicitly as a parameter using SpeechRecognizer construct.

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

In the following 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 the following 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 the following example, the source language is provided explicitly as a parameter using the FromConfig method.

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

In the following 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 the following 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 the following example, the source language is provided explicitly when creating a new SpeechRecognizer.

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

In the following 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 the following 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

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

speech_recognizer = speechsdk.SpeechRecognizer(
        speech_config=speech_config, language="de-DE", audio_config=audio_config)

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

source_language_config = speechsdk.languageconfig.SourceLanguageConfig("de-DE")
speech_recognizer = speechsdk.SpeechRecognizer(
        speech_config=speech_config, source_language_config=source_language_config, audio_config=audio_config)

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

source_language_config = speechsdk.languageconfig.SourceLanguageConfig("de-DE", "The Endpoint ID for your custom model.")
speech_recognizer = speechsdk.SpeechRecognizer(
        speech_config=speech_config, source_language_config=source_language_config, audio_config=audio_config)

Note

speech_recognition_language and endpoint_id properties are deprecated from the SpeechConfig class in Python. The use of these properties is discouraged, and they shouldn't be used when constructing a SpeechRecognizer.

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

In the following example, the source language is provided explicitly as a parameter using SPXSpeechRecognizer construct.

SPXSpeechRecognizer* speechRecognizer = \
    [[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig language:@"de-DE" audioConfiguration:audioConfig];

In the following example, the source language is provided using SPXSourceLanguageConfiguration. Then, the SPXSourceLanguageConfiguration is passed as a parameter to SPXSpeechRecognizer construct.

SPXSourceLanguageConfiguration* sourceLanguageConfig = [[SPXSourceLanguageConfiguration alloc]init:@"de-DE"];
SPXSpeechRecognizer* speechRecognizer = [[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig
                                                                     sourceLanguageConfiguration:sourceLanguageConfig
                                                                              audioConfiguration:audioConfig];

In the following example, the source language and custom endpoint are provided using SPXSourceLanguageConfiguration. Then, the SPXSourceLanguageConfiguration is passed as a parameter to SPXSpeechRecognizer construct.

SPXSourceLanguageConfiguration* sourceLanguageConfig = \
        [[SPXSourceLanguageConfiguration alloc]initWithLanguage:@"de-DE"
                                                     endpointId:@"The Endpoint ID for your custom model."];
SPXSpeechRecognizer* speechRecognizer = [[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig
                                                                     sourceLanguageConfiguration:sourceLanguageConfig
                                                                              audioConfiguration:audioConfig];

Note

speechRecognitionLanguage and endpointId properties are deprecated from the SPXSpeechConfiguration class in Objective-C. The use of these properties is discouraged, and they shouldn't be used when constructing a SPXSpeechRecognizer.

See also

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

Next steps