Skip to content

Commit bca9aed

Browse files
authored
Merge pull request #108859 from susanhuhu/susan-pr/pythondoc
Added python docs for language id
2 parents c9d29e3 + 922fa49 commit bca9aed

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.subservice: speech-service
1010
ms.topic: conceptual
1111
ms.date: 03/16/2020
1212
ms.author: dapine
13-
zone_pivot_groups: programming-languages-set-thirteen
13+
zone_pivot_groups: programming-languages-set-two
1414
---
1515

1616
# Automatic language detection for speech to text
@@ -20,7 +20,7 @@ Automatic language detection is used to determine the most likely match for audi
2020
In this article, you'll learn how to use `AutoDetectSourceLanguageConfig` to construct a `SpeechRecognizer` object and retrieve the detected language.
2121

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

@@ -97,6 +97,22 @@ result.close();
9797

9898
::: zone-end
9999

100+
::: zone pivot="programming-language-python"
101+
102+
```Python
103+
auto_detect_source_language_config = \
104+
speechsdk.languageconfig.AutoDetectSourceLanguageConfig(languages=["en-US", "de-DE"])
105+
speech_recognizer = speechsdk.SpeechRecognizer(
106+
speech_config=speech_config,
107+
auto_detect_source_language_config=auto_detect_source_language_config,
108+
audio_config=audio_config)
109+
result = speech_recognizer.recognize_once()
110+
auto_detect_source_language_result = speechsdk.AutoDetectSourceLanguageResult(result)
111+
detected_language = auto_detect_source_language_result.language
112+
```
113+
114+
::: zone-end
115+
100116
## Use a custom model for automatic language detection
101117

102118
In addition to language detection using Speech service models, you can specify a custom model for enhanced recognition. If a custom model isn't provided, the service will use the default language model.
@@ -150,6 +166,17 @@ AutoDetectSourceLanguageConfig autoDetectSourceLanguageConfig =
150166

151167
::: zone-end
152168

169+
::: zone pivot="programming-language-python"
170+
171+
```Python
172+
en_language_config = speechsdk.languageconfig.SourceLanguageConfig("en-US")
173+
fr_language_config = speechsdk.languageconfig.SourceLanguageConfig("fr-FR", "The Endpoint Id for custom model of fr-FR")
174+
auto_detect_source_language_config = speechsdk.languageconfig.AutoDetectSourceLanguageConfig(
175+
sourceLanguageConfigs=[en_language_config, fr_language_config])
176+
```
177+
178+
::: zone-end
179+
153180
## Next steps
154181

155182
- [Speech SDK reference documentation](speech-sdk.md)

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,32 @@ SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, sourceLanguageC
109109

110110
## How to specify source language in Python
111111

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

114114
```Python
115-
speech_key, service_region = "YourSubscriptionKey", "YourServiceRegion"
116-
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
115+
speech_recognizer = speechsdk.SpeechRecognizer(
116+
speech_config=speech_config, language="de-DE", audio_config=audio_config)
117117
```
118118

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

121121
```Python
122-
speech_config.speech_recognition_language="de-DE"
122+
source_language_config = speechsdk.languageconfig.SourceLanguageConfig("de-DE")
123+
speech_recognizer = speechsdk.SpeechRecognizer(
124+
speech_config=speech_config, source_language_config=source_language_config, audio_config=audio_config)
123125
```
124126

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

127129
```Python
128-
speech_config.endpoint_id = "The Endpoint ID for your custom model."
130+
source_language_config = speechsdk.languageconfig.SourceLanguageConfig("de-DE", "The Endpoint ID for your custom model.")
131+
speech_recognizer = speechsdk.SpeechRecognizer(
132+
speech_config=speech_config, source_language_config=source_language_config, audio_config=audio_config)
129133
```
130134

135+
>[!Note]
136+
> `speech_recognition_language` and `endpoint_id` properties are deprecated from the `SpeechConfig` class in Python. The use of these properties are discouraged, and shouldn't be used when constructing a `SpeechRecognizer`.
137+
131138
::: zone-end
132139

133140
::: zone pivot="programming-language-more"

0 commit comments

Comments
 (0)