Skip to content

Commit 30522a2

Browse files
committed
Added c# lid and source lang config doc
1 parent 35c1e4e commit 30522a2

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

articles/cognitive-services/Speech-Service/how-to-automatic-language-detection.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Automatic language detection is used to determine the most likely match for audi
1919
In this article, you'll learn how to use `AutoDetectSourceLanguageConfig` to construct a `SpeechRecognizer` object and retrieve the detected language.
2020

2121
> [!IMPORTANT]
22-
> This feature is only available for the Speech SDK for C++ and the Speech SDK for Java.
22+
> This feature is only available for the Speech SDK for C#, C++ and Java.
2323
2424
## Automatic language detection with the Speech SDK
2525

@@ -30,6 +30,17 @@ Automatic language detection currently has a services-side limit of two language
3030
3131
The following snippets illustrate how to use automatic language detection in your apps:
3232

33+
```csharp
34+
var autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig.FromLanguages(new string[] { "en-US", "de-DE" });
35+
using (var recognizer = new SpeechRecognizer(speechConfig, autoDetectSourceLanguageConfig, audioConfig))
36+
{
37+
var speechRecognitionResult = await recognizer.RecognizeOnceAsync();
38+
var autoDetectSourceLanguageResult = AutoDetectSourceLanguageResult.FromResult(speechRecognitionResult);
39+
var detectedLanguage = autoDetectSourceLanguageResult.Language;
40+
Assert.AreEqual(Language.DE_DE, detectedLanguage);
41+
}
42+
```
43+
3344
```C++
3445
auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "de-DE" });
3546
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig);
@@ -59,6 +70,15 @@ In addition to language detection using Speech service models, you can specify a
5970

6071
The snippets below illustrate how to specify a custom model in your call to the Speech service. If the detected language is `en-US`, then the default model is used. If the detected language is `fr-FR`, then the endpoint for the custom model is used:
6172

73+
```csharp
74+
var sourceLanguageConfigs = new SourceLanguageConfig[]
75+
{
76+
SourceLanguageConfig.FromLanguage("en-US"),
77+
SourceLanguageConfig.FromLanguage("fr-FR", "The Endpoint Id for custom model of fr-FR")
78+
};
79+
var autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig.FromSourceLanguageConfigs(sourceLanguageConfigs);
80+
```
81+
6282
```C++
6383
std::vector<std::shared_ptr<SourceLanguageConfig>> sourceLanguageConfigs;
6484
sourceLanguageConfigs.push_back(SourceLanguageConfig::FromLanguage("en-US"));

articles/cognitive-services/Speech-Service/how-to-specify-source-language.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ In this article, you'll learn how to specify the source language for an audio in
2121

2222
## How to specify source language in C#
2323

24-
The first step is to create a `SpeechConfig`:
24+
In this example, the source language is provided explicitly as a parameter using `SpeechRecognizer` construct.
2525

2626
```csharp
27-
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
27+
var recognizer = new SpeechRecognizer(speechConfig, "de-DE", audioConfig);
2828
```
2929

30-
Next, specify the source language of your audio with `SpeechRecognitionLanguage`:
30+
In this example, the source language is provided using `SourceLanguageConfig`. Then, the `sourceLanguageConfig` is passed as a parameter to `SpeechRecognizer` construct.
3131

3232
```csharp
33-
speechConfig.SpeechRecognitionLanguage = "de-DE";
33+
var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("de-DE");
34+
var recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);
3435
```
3536

36-
If you're using a custom model for recognition, you can specify the endpoint with `EndpointId`:
37+
In this example, the source language and custom endpoint are provided using `SourceLanguageConfig`. Then, the `sourceLanguageConfig` is passed as a parameter to `SpeechRecognizer` construct.
3738

3839
```csharp
39-
speechConfig.EndpointId = "The Endpoint ID for your custom model.";
40+
var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("de-DE", "The Endpoint ID for your custom model.");
41+
var recognizer = new SpeechRecognizer(speechConfig, sourceLanguageConfig, audioConfig);
4042
```
4143

44+
>[!Note]
45+
> `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`.
46+
4247
::: zone-end
4348

4449
::: zone pivot="programming-language-cpp"

0 commit comments

Comments
 (0)