@@ -35,56 +35,49 @@ Follow these steps to create a new console application and install the Speech SD
35
35
1. Replace the contents of `main.cpp` with the following code:
36
36
37
37
```cpp
38
- #include "stdafx.h"
39
38
#include <iostream>
40
39
#include <speechapi_cxx.h>
41
-
42
- using namespace std;
40
+
43
41
using namespace Microsoft::CognitiveServices::Speech;
44
42
using namespace Microsoft::CognitiveServices::Speech::Audio;
45
-
43
+
46
44
auto YourSubscriptionKey = "YourSubscriptionKey";
47
45
auto YourServiceRegion = "YourServiceRegion";
48
-
49
- void recognizeFromMicrophone ()
46
+
47
+ int main ()
50
48
{
51
49
auto speechConfig = SpeechConfig::FromSubscription(YourSubscriptionKey, YourServiceRegion);
52
50
speechConfig->SetSpeechRecognitionLanguage("en-US");
53
51
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");
56
54
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";
60
58
auto result = recognizer->RecognizeOnceAsync().get();
61
-
59
+
62
60
if (result->Reason == ResultReason::RecognizedSpeech)
63
61
{
64
- cout << "RECOGNIZED: Text=" << result->Text << std::endl;
62
+ std:: cout << "RECOGNIZED: Text=" << result->Text << std::endl;
65
63
}
66
64
else if (result->Reason == ResultReason::NoMatch)
67
65
{
68
- cout << "NOMATCH: Speech could not be recognized." << std::endl;
66
+ std:: cout << "NOMATCH: Speech could not be recognized." << std::endl;
69
67
}
70
68
else if (result->Reason == ResultReason::Canceled)
71
69
{
72
70
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
+
75
73
if (cancellation->Reason == CancellationReason::Error)
76
74
{
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;
80
78
}
81
79
}
82
- }
83
-
84
- int main()
85
- {
86
- recognizeFromMicrophone();
87
- }
80
+ }
88
81
```
89
82
90
83
1. In `main.cpp`, replace `YourSubscriptionKey` with your Speech resource key, and replace `YourServiceRegion` with your Speech resource region.
0 commit comments