Skip to content

Commit 2582cb9

Browse files
authored
std in and out
1 parent de0cb61 commit 2582cb9

File tree

1 file changed

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

1 file changed

+23
-27
lines changed

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: cognitive-services
44
ms.topic: include
5-
ms.date: 03/15/2022
5+
ms.date: 09/27/2022
66
ms.author: eur
77
---
88

@@ -42,56 +42,56 @@ Follow these steps to create a new console application and install the Speech SD
4242
#include <iostream>
4343
#include <stdlib.h>
4444
#include <speechapi_cxx.h>
45-
45+
4646
using namespace Microsoft::CognitiveServices::Speech;
4747
using namespace Microsoft::CognitiveServices::Speech::Audio;
48-
48+
4949
std::string getEnvironmentVariable(const char* name);
50-
50+
5151
int main()
5252
{
5353
auto speechKey = getEnvironmentVariable("SPEECH_KEY");
5454
auto speechRegion = getEnvironmentVariable("SPEECH_REGION");
55-
55+
5656
if ((size(speechKey) == 0) || (size(speechRegion) == 0)) {
5757
std::cout << "Please set both SPEECH_KEY and SPEECH_REGION environment variables." << std::endl;
5858
return -1;
5959
}
60-
60+
6161
auto speechConfig = SpeechConfig::FromSubscription(speechKey, speechRegion);
62-
62+
6363
// The language of the voice that speaks.
6464
speechConfig->SetSpeechSynthesisVoiceName("en-US-JennyNeural");
65-
65+
6666
auto speechSynthesizer = SpeechSynthesizer::FromConfig(speechConfig);
67-
67+
6868
// Get text from the console and synthesize to the default speaker.
69-
cout << "Enter some text that you want to speak >" << std::endl;
69+
std::cout << "Enter some text that you want to speak >" << std::endl;
7070
std::string text;
71-
getline(cin, text);
72-
71+
getline(std::cin, text);
72+
7373
auto result = speechSynthesizer->SpeakTextAsync(text).get();
74-
74+
7575
// Checks result.
7676
if (result->Reason == ResultReason::SynthesizingAudioCompleted)
7777
{
78-
cout << "Speech synthesized to speaker for text [" << text << "]" << std::endl;
78+
std::cout << "Speech synthesized to speaker for text [" << text << "]" << std::endl;
7979
}
8080
else if (result->Reason == ResultReason::Canceled)
8181
{
8282
auto cancellation = SpeechSynthesisCancellationDetails::FromResult(result);
83-
cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
84-
83+
std::cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
84+
8585
if (cancellation->Reason == CancellationReason::Error)
8686
{
87-
cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
88-
cout << "CANCELED: ErrorDetails=[" << cancellation->ErrorDetails << "]" << std::endl;
89-
cout << "CANCELED: Did you set the speech resource key and region values?" << std::endl;
87+
std::cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
88+
std::cout << "CANCELED: ErrorDetails=[" << cancellation->ErrorDetails << "]" << std::endl;
89+
std::cout << "CANCELED: Did you set the speech resource key and region values?" << std::endl;
9090
}
9191
}
92-
93-
cout << "Press enter to exit..." << std::endl;
94-
cin.get();
92+
93+
std::cout << "Press enter to exit..." << std::endl;
94+
std::cin.get();
9595
}
9696
9797
std::string getEnvironmentVariable(const char* name)
@@ -110,17 +110,13 @@ Follow these steps to create a new console application and install the Speech SD
110110
auto value = getenv(name);
111111
return value ? value : "";
112112
#endif
113-
}
113+
}
114114
```
115115
116116
1. To change the speech synthesis language, replace `en-US-JennyNeural` with another [supported voice](~/articles/cognitive-services/speech-service/supported-languages.md#prebuilt-neural-voices). All neural voices are multilingual and fluent in their own language and English. For example, if the input text in English is "I'm excited to try text to speech" and you set `es-ES-ElviraNeural`, the text is spoken in English with a Spanish accent. If the voice does not speak the language of the input text, the Speech service won't output synthesized audio.
117117
118118
Build and run your new console application to start speech synthesis to the default speaker.
119119
120-
```console
121-
dotnet run
122-
```
123-
124120
Enter some text that you want to speak. For example, type "I'm excited to try text to speech." Press the Enter key to hear the synthesized speech.
125121
126122
```console

0 commit comments

Comments
 (0)