Skip to content

Commit c3ff0d1

Browse files
authored
Merge pull request #202297 from eric-urban/eur/lid-java
java supports stt lid
2 parents bfeee13 + 5bca1f7 commit c3ff0d1

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

articles/cognitive-services/Speech-Service/language-identification.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: speech-service
1010
ms.topic: how-to
11-
ms.date: 06/13/2022
11+
ms.date: 06/21/2022
1212
ms.author: eur
1313
zone_pivot_groups: programming-languages-speech-services-nomore-variant
1414
---
@@ -99,7 +99,7 @@ For more information, see [supported languages](language-support.md#language-ide
9999
Speech supports both at-start and continuous language identification (LID).
100100
101101
> [!NOTE]
102-
> Continuous language identification is only supported with Speech SDKs in C#, C++, and Python.
102+
> Continuous language identification is only supported with Speech SDKs in C#, C++, Java ([for speech to text only](#speech-to-text)), and Python.
103103
- At-start LID identifies the language once within the first few seconds of audio. Use at-start LID if the language in the audio won't change.
104104
- Continuous LID can identify multiple languages for the duration of the audio. Use continuous LID if the language in the audio could change. Continuous LID does not support changing languages within the same sentence. For example, if you are primarily speaking Spanish and insert some English words, it will not detect the language change per word.
105105
@@ -110,7 +110,7 @@ You implement at-start LID or continuous LID by calling methods for [recognize o
110110
You can choose to prioritize accuracy or latency with language identification.
111111
112112
> [!NOTE]
113-
> Latency is prioritized by default with the Speech SDK. You can choose to prioritize accuracy or latency with the Speech SDKs for C#, C++, and Python.
113+
> Latency is prioritized by default with the Speech SDK. You can choose to prioritize accuracy or latency with the Speech SDKs for C#, C++, Java ([for speech to text only](#speech-to-text)), and Python.
114114
Prioritize `Latency` if you need a low-latency result such as during live streaming. Set the priority to `Accuracy` if the audio quality may be poor, and more latency is acceptable. For example, a voicemail could have background noise, or some silence at the beginning. Allowing the engine more time will improve language identification results.
115115
116116
* **At-start:** With at-start LID in `Latency` mode the result is returned in less than 5 seconds. With at-start LID in `Accuracy` mode the result is returned within 30 seconds. You set the priority for at-start LID with the `SpeechServiceConnection_SingleLanguageIdPriority` property.
@@ -128,6 +128,7 @@ speechConfig.SetProperty(PropertyId.SpeechServiceConnection_ContinuousLanguageId
128128
```
129129
130130
::: zone-end
131+
131132
::: zone pivot="programming-language-cpp"
132133
Here is an example of using continuous LID while still prioritizing latency.
133134
@@ -136,6 +137,17 @@ speechConfig->SetProperty(PropertyId::SpeechServiceConnection_ContinuousLanguage
136137
```
137138
138139
::: zone-end
140+
141+
::: zone pivot="programming-language-java"
142+
Here is an example of using continuous LID while still prioritizing latency.
143+
144+
```java
145+
speechConfig.setProperty(PropertyId.SpeechServiceConnection_ContinuousLanguageIdPriority, "Latency");
146+
```
147+
148+
::: zone-end
149+
150+
139151
::: zone pivot="programming-language-python"
140152
Here is an example of using continuous LID while still prioritizing latency.
141153
@@ -198,6 +210,23 @@ recognizer->StartContinuousRecognitionAsync().get();
198210
recognizer->StopContinuousRecognitionAsync().get();
199211
```
200212
213+
::: zone-end
214+
::: zone pivot="programming-language-java"
215+
216+
```java
217+
// Recognize once with At-start LID
218+
SpeechRecognitionResult result = recognizer->RecognizeOnceAsync().get();
219+
220+
// Start and stop continuous recognition with At-start LID
221+
recognizer.startContinuousRecognitionAsync().get();
222+
recognizer.stopContinuousRecognitionAsync().get();
223+
224+
// Start and stop continuous recognition with Continuous LID
225+
speechConfig.setProperty(PropertyId.SpeechServiceConnection_ContinuousLanguageIdPriority, "Latency");
226+
recognizer.startContinuousRecognitionAsync().get();
227+
recognizer.stopContinuousRecognitionAsync().get();
228+
```
229+
201230
::: zone-end
202231
::: zone pivot="programming-language-python"
203232
@@ -206,13 +235,13 @@ recognizer->StopContinuousRecognitionAsync().get();
206235
result = recognizer.recognize_once()
207236

208237
# Start and stop continuous recognition with At-start LID
209-
source_language_recognizer.start_continuous_recognition()
210-
source_language_recognizer.stop_continuous_recognition()
238+
recognizer.start_continuous_recognition()
239+
recognizer.stop_continuous_recognition()
211240

212241
# Start and stop continuous recognition with Continuous LID
213242
speech_config.set_property(property_id=speechsdk.PropertyId.SpeechServiceConnection_ContinuousLanguageIdPriority, value='Latency')
214-
source_language_recognizer.start_continuous_recognition()
215-
source_language_recognizer.stop_continuous_recognition()
243+
recognizer.start_continuous_recognition()
244+
recognizer.stop_continuous_recognition()
216245
```
217246
218247
::: zone-end
@@ -276,7 +305,7 @@ See more examples of standalone language identification on [GitHub](https://gith
276305
You use Speech-to-text recognition when you need to identify the language in an audio source and then transcribe it to text. For more information, see [Speech-to-text overview](speech-to-text.md).
277306
278307
> [!NOTE]
279-
> Speech-to-text recognition with at-start language identification is supported with Speech SDKs in C#, C++, Python, Java, JavaScript, and Objective-C. Speech-to-text recognition with continuous language identification is only supported with Speech SDKs in C#, C++, and Python.
308+
> Speech-to-text recognition with at-start language identification is supported with Speech SDKs in C#, C++, Python, Java, JavaScript, and Objective-C. Speech-to-text recognition with continuous language identification is only supported with Speech SDKs in C#, C++, Java, and Python.
280309
> Currently for speech-to-text recognition with continuous language identification, you must create a SpeechConfig from the `wss://{region}.stt.speech.microsoft.com/speech/universal/v2` endpoint string, as shown in code examples. In a future SDK release you won't need to set it.
281310

282311
::: zone pivot="programming-language-csharp"
@@ -431,12 +460,16 @@ auto detectedLanguage = autoDetectSourceLanguageResult->Language;
431460

432461
:::code language="cpp" source="~/samples-cognitive-services-speech-sdk/samples/cpp/windows/console/samples/speech_recognition_samples.cpp" id="SpeechContinuousRecognitionAndLanguageIdWithMultiLingualFile":::
433462

463+
---
464+
434465
::: zone-end
435466

436467
::: zone pivot="programming-language-java"
437468

438469
See more examples of speech-to-text recognition with language identification on [GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/jre/console/src/com/microsoft/cognitiveservices/speech/samples/console/SpeechRecognitionSamples.java).
439470

471+
### [Recognize once](#tab/once)
472+
440473
```java
441474
AutoDetectSourceLanguageConfig autoDetectSourceLanguageConfig =
442475
AutoDetectSourceLanguageConfig.fromLanguages(Arrays.asList("en-US", "de-DE"));
@@ -458,8 +491,14 @@ autoDetectSourceLanguageConfig.close();
458491
audioConfig.close();
459492
result.close();
460493
```
494+
495+
### [Continuous recognition](#tab/continuous)
496+
497+
:::code language="java" source="~/samples-cognitive-services-speech-sdk/samples/java/jre/console/src/com/microsoft/cognitiveservices/speech/samples/console/SpeechRecognitionSamples.java" id="SpeechContinuousRecognitionAndLanguageId":::
498+
461499
---
462500

501+
463502
::: zone-end
464503

465504
::: zone pivot="programming-language-python"

0 commit comments

Comments
 (0)