Skip to content

Commit 97f06e6

Browse files
authored
Merge pull request #189704 from trrwilson/patch-10
[Cog Svcs] Speech SDK C++ quickstart compilation fix + minor adjustments
2 parents 0eb251a + 0029eeb commit 97f06e6

File tree

1 file changed

+18
-25
lines changed
  • articles/cognitive-services/Speech-Service/includes/quickstarts/speech-to-text-basics

1 file changed

+18
-25
lines changed

articles/cognitive-services/Speech-Service/includes/quickstarts/speech-to-text-basics/cpp.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,49 @@ Follow these steps to create a new console application and install the Speech SD
3535
1. Replace the contents of `main.cpp` with the following code:
3636
3737
```cpp
38-
#include "stdafx.h"
3938
#include <iostream>
4039
#include <speechapi_cxx.h>
41-
42-
using namespace std;
40+
4341
using namespace Microsoft::CognitiveServices::Speech;
4442
using namespace Microsoft::CognitiveServices::Speech::Audio;
45-
43+
4644
auto YourSubscriptionKey = "YourSubscriptionKey";
4745
auto YourServiceRegion = "YourServiceRegion";
48-
49-
void recognizeFromMicrophone()
46+
47+
int main()
5048
{
5149
auto speechConfig = SpeechConfig::FromSubscription(YourSubscriptionKey, YourServiceRegion);
5250
speechConfig->SetSpeechRecognitionLanguage("en-US");
5351
54-
//To recognize speech from an audio file, use `FromWavFileInput` instead of `FromDefaultMicrophoneInput`:
55-
//auto audioInput = AudioConfig::FromWavFileInput("YourAudioFile.wav");
52+
// To recognize speech from an audio file, use `FromWavFileInput` instead of `FromDefaultMicrophoneInput`:
53+
// auto audioInput = AudioConfig::FromWavFileInput("YourAudioFile.wav");
5654
auto audioConfig = AudioConfig::FromDefaultMicrophoneInput();
57-
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, audioConfig);
58-
59-
cout << "Speak into your microphone.\n";
55+
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, audioConfig);
56+
57+
std::cout << "Speak into your microphone.\n";
6058
auto result = recognizer->RecognizeOnceAsync().get();
61-
59+
6260
if (result->Reason == ResultReason::RecognizedSpeech)
6361
{
64-
cout << "RECOGNIZED: Text=" << result->Text << std::endl;
62+
std::cout << "RECOGNIZED: Text=" << result->Text << std::endl;
6563
}
6664
else if (result->Reason == ResultReason::NoMatch)
6765
{
68-
cout << "NOMATCH: Speech could not be recognized." << std::endl;
66+
std::cout << "NOMATCH: Speech could not be recognized." << std::endl;
6967
}
7068
else if (result->Reason == ResultReason::Canceled)
7169
{
7270
auto cancellation = CancellationDetails::FromResult(result);
73-
cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
74-
71+
std::cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
72+
7573
if (cancellation->Reason == CancellationReason::Error)
7674
{
77-
cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
78-
cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
79-
cout << "CANCELED: Double check the speech resource key and region" << std::endl;
75+
std::cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
76+
std::cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
77+
std::cout << "CANCELED: Double check the speech resource key and region" << std::endl;
8078
}
8179
}
82-
}
83-
84-
int main()
85-
{
86-
recognizeFromMicrophone();
87-
}
80+
}
8881
```
8982
9083
1. In `main.cpp`, replace `YourSubscriptionKey` with your Speech resource key, and replace `YourServiceRegion` with your Speech resource region.

0 commit comments

Comments
 (0)