Skip to content

Commit c6aa605

Browse files
committed
[CogSvcs] reco modes doc
1 parent c921f55 commit c6aa605

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
title: Choosing a speech recognition mode with the Speech SDK
3+
titleSuffix: Azure Cognitive Services
4+
description: Learn how to choose the best recognition mode when using the Speech SDK.
5+
services: cognitive-services
6+
author: IEvangelist
7+
manager: nitinme
8+
ms.service: cognitive-services
9+
ms.subservice: speech-service
10+
ms.topic: conceptual
11+
ms.date: 01/10/2020
12+
ms.author: dapine
13+
---
14+
15+
# Choosing a speech recognition mode
16+
17+
When considering speech-to-text recognition operations, the [Speech SDK](speech-sdk.md) provides multiple modes for processing speech. Conceptually, sometimes called the *recognition mode*. This article compares the various recognition modes.
18+
19+
## Recognize once
20+
21+
If you want to process each utterance one "sentence" at a time, use the "recognize once" function. This method will detect a recognized utterance from the input starting at the beginning of detected speech until the next pause. Usually, a pause marks the end of a sentence or line-of-thought.
22+
23+
At the end of one recognized utterance, the service stops processing audio from that request. The maximum limit for recognition is a sentence duration of 20 seconds.
24+
25+
# [C#](#tab/csharp)
26+
27+
For more information on using the `RecognizeOnceAsync` function, see the [.NET Speech SDK docs](https://docs.microsoft.com/dotnet/api/microsoft.cognitiveservices.speech.speechrecognizer.recognizeonceasync?view=azure-dotnet#Microsoft_CognitiveServices_Speech_SpeechRecognizer_RecognizeOnceAsync).
28+
29+
```csharp
30+
var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);
31+
```
32+
33+
# [C++](#tab/cpp)
34+
35+
For more information on using the `RecognizeOnceAsync` function, see the [C++ Speech SDK docs](https://docs.microsoft.com/cpp/cognitive-services/speech/asyncrecognizer#recognizeonceasync).
36+
37+
```cpp
38+
auto result = recognize->RecognizeOnceAsync().get();
39+
```
40+
41+
# [Java](#tab/java)
42+
43+
For more information on using the `recognizeOnceAsync` function, see the [Java Speech SDK docs](https://docs.microsoft.com/java/api/com.microsoft.cognitiveservices.speech.SpeechRecognizer.recognizeOnceAsync?view=azure-java-stable).
44+
45+
```java
46+
SpeechRecognitionResult result = recognizer.recognizeOnceAsync().get();
47+
```
48+
49+
# [Python](#tab/python)
50+
51+
For more information on using the `recognize_once` function, see the [Python Speech SDK docs](https://docs.microsoft.com/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechrecognizer?view=azure-python#recognize-once------azure-cognitiveservices-speech-speechrecognitionresult).
52+
53+
```python
54+
result = speech_recognizer.recognize_once()
55+
```
56+
57+
***
58+
59+
## Continuous
60+
61+
If you need long-running recognition, use the start and corresponding stop functions for continuous recognition. The start function will start and continue processing all utterances until you invoke the stop function, or until too much time in silence has passed. When using the continuous mode, be sure to register to the various events that will fire upon occurrence. For example, the "recognized" event fires when speech recognition occurs. You need to have an event handler in place to handle recognition. A limit of 10 minutes of total speech recognition time, per session is enforced by the Speech service.
62+
63+
# [C#](#tab/csharp)
64+
65+
```csharp
66+
// Subscribe to event
67+
recognizer.Recognized += (s, e) =>
68+
{
69+
if (e.Result.Reason == ResultReason.RecognizedSpeech)
70+
{
71+
// Do something with the recognized text
72+
// e.Result.Text
73+
}
74+
};
75+
76+
// Start continuous speech recognition
77+
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
78+
79+
// Stop continuous speech recognition
80+
await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
81+
```
82+
83+
# [C++](#tab/cpp)
84+
85+
```cpp
86+
// Connect to event
87+
recognizer->Recognized.Connect([] (const SpeechRecognitionEventArgs& e)
88+
{
89+
if (e.Result->Reason == ResultReason::RecognizedSpeech)
90+
{
91+
// Do something with the recognized text
92+
// e.Result->Text
93+
}
94+
});
95+
96+
// Start continuous speech recognition
97+
recognizer->StartContinuousRecognitionAsync().get();
98+
99+
// Stop continuous speech recognition
100+
recognizer->StopContinuousRecognitionAsync().get();
101+
```
102+
103+
# [Java](#tab/java)
104+
105+
```java
106+
recognizer.recognized.addEventListener((s, e) -> {
107+
if (e.getResult().getReason() == ResultReason.RecognizedSpeech) {
108+
// Do something with the recognized text
109+
// e.getResult().getText()
110+
}
111+
});
112+
113+
// Start continuous speech recognition
114+
recognizer.startContinuousRecognitionAsync().get();
115+
116+
// Stop continuous speech recognition
117+
recognizer.stopContinuousRecognitionAsync().get();
118+
```
119+
120+
# [Python](#tab/python)
121+
122+
```python
123+
def recognized_cb(evt):
124+
if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech:
125+
# Do something with the recognized text
126+
# evt.result.text
127+
128+
speech_recognizer.recognized.connect(recognized_cb)
129+
130+
# Start continuous speech recognition
131+
speech_recognizer.start_continuous_recognition()
132+
133+
# Stop continuous speech recognition
134+
speech_recognizer.stop_continuous_recognition()
135+
```
136+
137+
***
138+
139+
## Dictation
140+
141+
When using continuous recognition, you can enable dictation processing by using the corresponding "enable dictation" function. This mode will cause the speech config instance to interpret word descriptions of sentence structures such as punctuation. For example, the utterance "Do you live in town question mark" would be interpreted as the text "Do you live in town?".
142+
143+
# [C#](#tab/csharp)
144+
145+
For more information on using the `EnableDictation` function, see the [.NET Speech SDK docs](https://docs.microsoft.com/dotnet/api/microsoft.cognitiveservices.speech.speechconfig.enabledictation?view=azure-dotnet#Microsoft_CognitiveServices_Speech_SpeechConfig_EnableDictation).
146+
147+
```csharp
148+
SpeechConfig.EnableDictation();
149+
```
150+
151+
# [C++](#tab/cpp)
152+
153+
For more information on using the `EnableDictation` function, see the [C++ Speech SDK docs](https://docs.microsoft.com/cpp/cognitive-services/speech/speechconfig#enabledictation).
154+
155+
```cpp
156+
SpeechConfig->EnableDictation();
157+
```
158+
159+
# [Java](#tab/java)
160+
161+
For more information on using the `enableDictation` function, see the [Java Speech SDK docs](https://docs.microsoft.com/java/api/com.microsoft.cognitiveservices.speech.SpeechConfig.enableDictation?view=azure-java-stable).
162+
163+
```java
164+
SpeechConfig.enableDictation();
165+
```
166+
167+
# [Python](#tab/python)
168+
169+
For more information on using the `recognize_once` function, see the [Python Speech SDK docs](https://docs.microsoft.com/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechconfig?view=azure-python#enable-dictation--).
170+
171+
```python
172+
SpeechConfig.enable_dictation()
173+
```
174+
175+
***
176+
177+
## Next steps
178+
179+
If you're looking for additional Speech SDK language coverage, see all the [Speech SDK samples](https://aka.ms/speech/github) on GitHub.
180+
181+
> [!div class="nextstepaction"]
182+
> [Explore our samples on GitHub](https://aka.ms/csspeech/samples)

0 commit comments

Comments
 (0)