Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this article, you'll learn how to specify the source language for an audio input passed to the Speech SDK for speech recognition. The example code that's provided specifies a custom speech model for improved recognition.
Specify source language in C#
In the following example, the source language is provided explicitly as a parameter by using the SpeechRecognizer
construct:
var recognizer = new SpeechRecognizer(speechConfig, "de-DE", audioConfig);
In the following example, the source language is provided by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter to the 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 by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter to the SpeechRecognizer
construct.
var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("de-DE", "The Endpoint ID for your custom model.");
var recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);
Note
The SpeechRecognitionLanguage
and EndpointId
set methods are deprecated from the SpeechConfig
class in C#. The use of these methods is discouraged. Don't use them when you create a SpeechRecognizer
construct.
Specify source language in C++
In the following example, the source language is provided explicitly as a parameter by using the FromConfig
method.
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, "de-DE", audioConfig);
In the following example, the source language is provided by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter to FromConfig
when you create the recognizer
construct.
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 by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter to FromConfig
when you create the recognizer
construct.
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 is discouraged. Don't use them when you create a SpeechRecognizer
construct.
Specify source language in Java
In the following example, the source language is provided explicitly when you create a new SpeechRecognizer
construct.
SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, "de-DE", audioConfig);
In the following example, the source language is provided by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter when you create a new SpeechRecognizer
construct.
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 by using SourceLanguageConfig
. Then, sourceLanguageConfig
is passed as a parameter when you create a new SpeechRecognizer
construct.
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 is discouraged. Don't use them when you create a SpeechRecognizer
construct.
Specify source language in Python
In the following example, the source language is provided explicitly as a parameter by using the 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 by using SourceLanguageConfig
. Then, SourceLanguageConfig
is passed as a parameter to the 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 by using SourceLanguageConfig
. Then, SourceLanguageConfig
is passed as a parameter to the 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
The speech_recognition_language
and endpoint_id
properties are deprecated from the SpeechConfig
class in Python. The use of these properties is discouraged. Don't use them when you create a SpeechRecognizer
construct.
Specify source language in JavaScript
The first step is to create a SpeechConfig
construct:
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.";
Specify source language in Objective-C
In the following example, the source language is provided explicitly as a parameter by using the SPXSpeechRecognizer
construct.
SPXSpeechRecognizer* speechRecognizer = \
[[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig language:@"de-DE" audioConfiguration:audioConfig];
In the following example, the source language is provided by using SPXSourceLanguageConfiguration
. Then, SPXSourceLanguageConfiguration
is passed as a parameter to the 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 by using SPXSourceLanguageConfiguration
. Then, SPXSourceLanguageConfiguration
is passed as a parameter to the 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
The speechRecognitionLanguage
and endpointId
properties are deprecated from the SPXSpeechConfiguration
class in Objective-C. The use of these properties is discouraged. Don't use them when you create a SPXSpeechRecognizer
construct.