Skip to content

Commit 2a0e5ca

Browse files
authored
Merge pull request #100196 from erhopf/speech-cpp-update
[CogSvcs] Speech - C++ From File - Sample Updates
2 parents cd02672 + 993e4e3 commit 2a0e5ca

File tree

3 files changed

+10
-130
lines changed

3 files changed

+10
-130
lines changed

articles/cognitive-services/Speech-Service/includes/quickstarts/from-file/cpp/linux.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: 'Quickstart: Recognize speech from an audio file, C++ (Linux) - Speech service'
33
titleSuffix: Azure Cognitive Services
44
services: cognitive-services
5-
author: wolfma61
5+
author: erhopf
66
manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: speech-service
99
ms.topic: include
1010
ms.date: 01/14/2020
11-
ms.author: wolfma
11+
ms.author: erhopf
1212
---
1313

1414
## Prerequisites
@@ -26,47 +26,7 @@ Before you get started, make sure to:
2626

2727
1. Create a C++ source file named `helloworld.cpp`, and paste the following code into it.
2828

29-
```cpp
30-
// Creates an instance of a speech config with specified subscription key and service region.
31-
// Replace with your own subscription key and service region (e.g., "westus").
32-
auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
33-
34-
// Creates a speech recognizer using a WAV file. The default language is "en-us".
35-
// Replace with your own audio file name.
36-
auto audioInput = AudioConfig::FromWavFileInput("whatstheweatherlike.wav");
37-
auto recognizer = SpeechRecognizer::FromConfig(config, audioInput);
38-
cout << "Recognizing first result...\n";
39-
40-
// Starts speech recognition, and returns after a single utterance is recognized. The end of a
41-
// single utterance is determined by listening for silence at the end or until a maximum of 15
42-
// seconds of audio is processed. The task returns the recognition text as result.
43-
// Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
44-
// shot recognition like command or query.
45-
// For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
46-
auto result = recognizer->RecognizeOnceAsync().get();
47-
48-
// Checks result.
49-
switch (result->Reason)
50-
{
51-
case ResultReason::RecognizedSpeech:
52-
cout << "RECOGNIZED: Text=" << result->Text << std::endl;
53-
break;
54-
case ResultReason::NoMatch:
55-
cout << "NOMATCH: Speech could not be recognized." << std::endl;
56-
break;
57-
case ResultReason::Canceled:
58-
auto cancellation = CancellationDetails::FromResult(result);
59-
cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
60-
61-
if (cancellation->Reason == CancellationReason::Error)
62-
{
63-
cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
64-
cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
65-
cout << "CANCELED: Did you update the subscription info?" << std::endl;
66-
}
67-
break;
68-
}
69-
```
29+
[!code-cpp[Quickstart Code](~/samples-cognitive-services-speech-sdk/quickstart/cpp/windows/from-file/helloworld/helloworld.cpp#code)]
7030

7131
1. In this new file, replace the string `YourSubscriptionKey` with your Speech service subscription key.
7232

articles/cognitive-services/Speech-Service/includes/quickstarts/from-file/cpp/macos.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: 'Quickstart: Recognize speech from an audio file, C++ (macOS) - Speech service'
33
titleSuffix: Azure Cognitive Services
44
services: cognitive-services
5-
author: wolfma61
5+
author: erhopf
66
manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: speech-service
99
ms.topic: include
1010
ms.date: 01/14/2020
11-
ms.author: wolfma
11+
ms.author: erhopf
1212
---
1313

1414
## Prerequisites
@@ -26,47 +26,7 @@ Before you get started, make sure to:
2626

2727
1. Create a C++ source file named `helloworld.cpp`, and paste the following code into it.
2828

29-
```cpp
30-
// Creates an instance of a speech config with specified subscription key and service region.
31-
// Replace with your own subscription key and service region (e.g., "westus").
32-
auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
33-
34-
// Creates a speech recognizer using a WAV file. The default language is "en-us".
35-
// Replace with your own audio file name.
36-
auto audioInput = AudioConfig::FromWavFileInput("whatstheweatherlike.wav");
37-
auto recognizer = SpeechRecognizer::FromConfig(config, audioInput);
38-
cout << "Recognizing first result...\n";
39-
40-
// Starts speech recognition, and returns after a single utterance is recognized. The end of a
41-
// single utterance is determined by listening for silence at the end or until a maximum of 15
42-
// seconds of audio is processed. The task returns the recognition text as result.
43-
// Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
44-
// shot recognition like command or query.
45-
// For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
46-
auto result = recognizer->RecognizeOnceAsync().get();
47-
48-
// Checks result.
49-
switch (result->Reason)
50-
{
51-
case ResultReason::RecognizedSpeech:
52-
cout << "RECOGNIZED: Text=" << result->Text << std::endl;
53-
break;
54-
case ResultReason::NoMatch:
55-
cout << "NOMATCH: Speech could not be recognized." << std::endl;
56-
break;
57-
case ResultReason::Canceled:
58-
auto cancellation = CancellationDetails::FromResult(result);
59-
cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
60-
61-
if (cancellation->Reason == CancellationReason::Error)
62-
{
63-
cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
64-
cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
65-
cout << "CANCELED: Did you update the subscription info?" << std::endl;
66-
}
67-
break;
68-
}
69-
```
29+
[!code-cpp[Quickstart Code](~/samples-cognitive-services-speech-sdk/quickstart/cpp/windows/from-file/helloworld/helloworld.cpp#code)]
7030

7131
1. In this new file, replace the string `YourSubscriptionKey` with your Speech service subscription key.
7232

articles/cognitive-services/Speech-Service/includes/quickstarts/from-file/cpp/windows.md

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: 'Quickstart: Recognize speech from an audio file, C++ (Windows) - Speech service'
33
titleSuffix: Azure Cognitive Services
44
services: cognitive-services
5-
author: wolfma61
5+
author: erhopf
66
manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: speech-service
99
ms.topic: include
1010
ms.date: 01/14/2020
11-
ms.author: wolfma61
11+
ms.author: erhopf
1212
---
1313

1414
## Prerequisites
@@ -27,48 +27,8 @@ Before you get started, make sure to:
2727
1. Open the source file **helloworld.cpp**.
2828

2929
1. Replace all the code with the following snippet:
30-
31-
```cpp
32-
// Creates an instance of a speech config with specified subscription key and service region.
33-
// Replace with your own subscription key and service region (e.g., "westus").
34-
auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
35-
36-
// Creates a speech recognizer using a WAV file. The default language is "en-us".
37-
// Replace with your own audio file name.
38-
auto audioInput = AudioConfig::FromWavFileInput("whatstheweatherlike.wav");
39-
auto recognizer = SpeechRecognizer::FromConfig(config, audioInput);
40-
cout << "Recognizing first result...\n";
41-
42-
// Starts speech recognition, and returns after a single utterance is recognized. The end of a
43-
// single utterance is determined by listening for silence at the end or until a maximum of 15
44-
// seconds of audio is processed. The task returns the recognition text as result.
45-
// Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
46-
// shot recognition like command or query.
47-
// For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
48-
auto result = recognizer->RecognizeOnceAsync().get();
49-
50-
// Checks result.
51-
switch (result->Reason)
52-
{
53-
case ResultReason::RecognizedSpeech:
54-
cout << "RECOGNIZED: Text=" << result->Text << std::endl;
55-
break;
56-
case ResultReason::NoMatch:
57-
cout << "NOMATCH: Speech could not be recognized." << std::endl;
58-
break;
59-
case ResultReason::Canceled:
60-
auto cancellation = CancellationDetails::FromResult(result);
61-
cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
62-
63-
if (cancellation->Reason == CancellationReason::Error)
64-
{
65-
cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
66-
cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
67-
cout << "CANCELED: Did you update the subscription info?" << std::endl;
68-
}
69-
break;
70-
}
71-
```
30+
31+
[!code-cpp[Quickstart Code](~/samples-cognitive-services-speech-sdk/quickstart/cpp/windows/from-file/helloworld/helloworld.cpp#code)]
7232

7333
1. In the same file, replace the string `YourSubscriptionKey` with your subscription key.
7434

0 commit comments

Comments
 (0)