Skip to content

Commit 9567cb7

Browse files
Addressed code review concerns, updated sample to be be longer running. Updated copyright notices.
1 parent 000503e commit 9567cb7

File tree

15 files changed

+227
-189
lines changed

15 files changed

+227
-189
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/*
2-
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://aws.amazon.com/apache2.0
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
15-
16-
#define AWS_SDK_VERSION_STRING "1.0.65"
1+
/*
2+
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#define AWS_SDK_VERSION_STRING "1.0.65"

aws-cpp-sdk-polly-sample/main.cpp

Lines changed: 92 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
115

216
#include <aws/core/Aws.h>
317
#include <aws/text-to-speech/TextToSpeechManager.h>
@@ -6,65 +20,84 @@
620
using namespace Aws::Polly;
721
using namespace Aws::TextToSpeech;
822

23+
static const char* ALLOCATION_TAG = "PollySample::Main";
24+
25+
void DriveProgram();
26+
void SelectVoiceAndOutputSound(Aws::TextToSpeech::TextToSpeechManager& manager);
27+
928
int main()
1029
{
11-
Aws::SDKOptions options;
12-
Aws::InitAPI(options);
13-
{
14-
std::shared_ptr<PollyClient> client = Aws::MakeShared<PollyClient>("blah");
15-
TextToSpeechManager manager(client);
16-
17-
std::cout << "available devices are: " << std::endl;
18-
auto devices = manager.EnumerateDevices();
19-
20-
for (auto& device : devices)
21-
{
22-
std::cout << "[" << device.first.deviceId << "] " << device.first.deviceName << " Driver: "
23-
<< device.second->GetName() << std::endl;
24-
}
25-
26-
std::cout << "please select deviceid to play output to:" << std::endl;
27-
28-
Aws::String deviceId;
29-
std::getline(std::cin, deviceId);
30-
31-
for (auto& device : devices)
32-
{
33-
if (device.first.deviceId == deviceId)
34-
{
35-
manager.SetActiveDevice(device.second, device.first, device.first.capabilities[0]);
36-
}
37-
}
38-
39-
std::cout << "available voices are: " << std::endl;
40-
for (auto& voice : manager.ListAvailableVoices())
41-
{
42-
std::cout << voice.first << " language: " << voice.second << std::endl;
43-
}
44-
45-
std::cout << "please select voice you would like me to render." << std::endl;
46-
47-
Aws::String voice;
48-
std::getline(std::cin, voice);
49-
manager.SetActiveVoice(voice);
50-
51-
SendTextCompletedHandler handler;
52-
53-
std::cout << "What would you like me to say?" << std::endl;
54-
Aws::String line;
55-
while (std::getline(std::cin, line))
56-
{
57-
if (line == "exit")
58-
{
59-
goto end;
60-
}
61-
62-
manager.SendTextToOutputDevice(line.c_str(), handler);
63-
std::cout << "Anything else?" << std::endl;
64-
}
65-
}
66-
67-
end:
68-
Aws::ShutdownAPI(options);
69-
return 0;
30+
Aws::SDKOptions options;
31+
Aws::InitAPI(options);
32+
DriveProgram();
33+
Aws::ShutdownAPI(options);
34+
return 0;
35+
}
36+
37+
void SelectVoiceAndOutputSound(Aws::TextToSpeech::TextToSpeechManager& manager)
38+
{
39+
std::cout << "available voices are: " << std::endl;
40+
for (auto& voice : manager.ListAvailableVoices())
41+
{
42+
std::cout << voice.first << " language: " << voice.second << std::endl;
43+
}
44+
45+
std::cout << "please select voice you would like me to render." << std::endl;
46+
47+
Aws::String voice;
48+
std::getline(std::cin, voice);
49+
manager.SetActiveVoice(voice);
50+
51+
SendTextCompletedHandler handler;
52+
53+
std::cout << "What would you like me to say?" << std::endl;
54+
Aws::String line;
55+
while (std::getline(std::cin, line))
56+
{
57+
if (line == "exit")
58+
{
59+
return;
60+
}
61+
if (line == "change voice")
62+
{
63+
SelectVoiceAndOutputSound(manager);
64+
return;
65+
}
66+
67+
manager.SendTextToOutputDevice(line.c_str(), handler);
68+
std::cout << "Anything else?" << std::endl;
69+
}
70+
}
71+
72+
void DriveProgram()
73+
{
74+
auto client = Aws::MakeShared<PollyClient>(ALLOCATION_TAG);
75+
TextToSpeechManager manager(client);
76+
77+
std::cout << "available devices are: " << std::endl;
78+
auto devices = manager.EnumerateDevices();
79+
80+
for (auto& device : devices)
81+
{
82+
std::cout << "[" << device.first.deviceId << "] " << device.first.deviceName << " Driver: "
83+
<< device.second->GetName() << std::endl;
84+
}
85+
86+
std::cout << "please select deviceid to play output to:" << std::endl;
87+
88+
Aws::String deviceId;
89+
std::getline(std::cin, deviceId);
90+
91+
auto foundDevice = std::find_if(devices.begin(), devices.end(),
92+
[&deviceId](const OutputDevicePair& device)
93+
{ return device.first.deviceId == deviceId; });
94+
95+
if (foundDevice == devices.end())
96+
{
97+
std::cout << "Invalid device selection." << std::endl;
98+
DriveProgram();
99+
return;
100+
}
101+
102+
SelectVoiceAndOutputSound(manager);
70103
}

aws-cpp-sdk-text-to-speech-tests/RunTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

aws-cpp-sdk-text-to-speech-tests/TextToSpeechManagerTests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -235,9 +235,9 @@ TEST(TextToSpeechManagerTests, TestDeviceListAndSelection)
235235
devInfo1.deviceName ="deviceName1";
236236

237237
CapabilityInfo capability;
238-
capability.sampleRate = 8000;
238+
capability.sampleRate = KHZ_8;
239239
devInfo1.capabilities.push_back(capability);
240-
capability.sampleRate = 16000;
240+
capability.sampleRate = KHZ_16;
241241
devInfo1.capabilities.push_back(capability);
242242
driver1->AddDevice(devInfo1);
243243

@@ -254,19 +254,19 @@ TEST(TextToSpeechManagerTests, TestDeviceListAndSelection)
254254
ASSERT_STREQ(devInfo1.deviceId.c_str(), devices[0].first.deviceId.c_str());
255255
ASSERT_STREQ(devInfo1.deviceName.c_str(), devices[0].first.deviceName.c_str());
256256
ASSERT_EQ(2u, devices[0].first.capabilities.size());
257-
ASSERT_EQ(8000u, devices[0].first.capabilities[0].sampleRate);
258-
ASSERT_EQ(16000u, devices[0].first.capabilities[1].sampleRate);
257+
ASSERT_EQ(KHZ_8, devices[0].first.capabilities[0].sampleRate);
258+
ASSERT_EQ(KHZ_16, devices[0].first.capabilities[1].sampleRate);
259259
ASSERT_EQ(devices[0].second, driver1);
260260

261261
ASSERT_STREQ(devInfo2.deviceId.c_str(), devices[1].first.deviceId.c_str());
262262
ASSERT_STREQ(devInfo2.deviceName.c_str(), devices[1].first.deviceName.c_str());
263263
ASSERT_EQ(1u, devices[1].first.capabilities.size());
264-
ASSERT_EQ(22050u, devices[1].first.capabilities[0].sampleRate);
264+
ASSERT_EQ(KHZ_22_5, devices[1].first.capabilities[0].sampleRate);
265265
ASSERT_EQ(devices[1].second, driver2);
266266

267267
manager.SetActiveDevice(driver2, devInfo2, devInfo2.capabilities[0]);
268268
ASSERT_STREQ(devInfo2.deviceId.c_str(), driver2->GetActiveDevice().deviceId.c_str());
269-
ASSERT_EQ(22050u, driver2->GetActiveCaps().sampleRate);
269+
ASSERT_EQ(KHZ_22_5, driver2->GetActiveCaps().sampleRate);
270270
}
271271

272272
TEST(TextToSpeechManagerTests, TestDeviceListEmpty)
@@ -308,7 +308,7 @@ TEST(TextToSpeechManagerTests, TestSynthResponseAndOutput)
308308
devInfo1.deviceName = "deviceName1";
309309

310310
CapabilityInfo capability;
311-
capability.sampleRate = 8000;
311+
capability.sampleRate = KHZ_8;
312312
devInfo1.capabilities.push_back(capability);
313313
driver1->AddDevice(devInfo1);
314314

@@ -368,7 +368,7 @@ TEST(TextToSpeechManagerTests, TestSynthRequestFailedAndNoOutput)
368368
devInfo1.deviceName = "deviceName1";
369369

370370
CapabilityInfo capability;
371-
capability.sampleRate = 8000;
371+
capability.sampleRate = KHZ_8;
372372
devInfo1.capabilities.push_back(capability);
373373

374374
manager.SetActiveDevice(driver1, devInfo1, capability);

aws-cpp-sdk-text-to-speech/CMakeLists.txt

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,52 @@ check_include_files("pulse/simple.h" HAVE_PULSE)
1313

1414
if(PLATFORM_WINDOWS)
1515
file( GLOB TEXT_TO_SPEECH_PLATFORM_HEADERS "include/aws/text-to-speech/windows/*.h" )
16+
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/windows/*.cpp" )
17+
18+
add_definitions("-DWAVE_OUT")
19+
set(PLATFORM_LIBS ${PLATFORM_LIBS} Winmm)
1620
endif()
1721

1822
if(HAVE_PULSE)
1923
file( GLOB TEXT_TO_SPEECH_PLATFORM_HEADERS "include/aws/text-to-speech/linux/*.h" )
24+
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/linux/*.cpp" )
25+
26+
message(STATUS "Pulse audio header files have been detected, included pulse audio as a possible sound driver implementation.")
27+
add_definitions("-DPULSE")
28+
set(PLATFORM_LIBS ${PLATFORM_LIBS} pulse-simple)
29+
elseif(PLATFORM_LINUX)
30+
message(WARNING "We've detected that you are building on linux, but the header files for pulseaudio are not available.\
31+
If you are providing your own audio implementation or you will not be using the text-to-speech library, this is fine.\
32+
However, if you are not providing your own implemenation and you want to use text-to-speech, you need to install the dev files for pulseudio.\
33+
e.g. apt-get install libpulse-dev or yum install pulseaudio-libs-devel. Currently, no audio implementation will be built into this library.")
2034
endif()
2135

2236
if(PLATFORM_APPLE)
2337
file( GLOB TEXT_TO_SPEECH_PLATFORM_HEADERS "include/aws/text-to-speech/apple/*.h" )
24-
endif()
38+
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/apple/*.cpp" )
2539

26-
file( GLOB TEXT_TO_SPEECH_SOURCE "source/text-to-speech/*.cpp" )
40+
find_library(COREAUDIO_LIBRARY CoreAudio)
41+
find_path(COREAUDIO_INCLUDE_DIR CoreAudioTypes.h)
2742

28-
if(PLATFORM_WINDOWS)
29-
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/windows/*.cpp" )
30-
endif()
43+
include_directories(${COREAUDIO_INCLUDE_DIR})
44+
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${COREAUDIO_LIBRARY})
3145

32-
if(HAVE_PULSE)
33-
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/linux/*.cpp" )
34-
endif()
46+
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
47+
find_path(AUDIOTOOLBOX_INCLUDE_DIR AudioQueue.h)
3548

36-
if(PLATFORM_APPLE)
37-
file( GLOB TEXT_TO_SPEECH_PLATFORM_SOURCE "source/text-to-speech/apple/*.cpp" )
49+
include_directories(${AUDIOTOOLBOX_INCLUDE_DIR})
50+
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${AUDIOTOOLBOX_LIBRARY})
51+
52+
find_library(FOUNDATION_LIBRARY CoreFoundation)
53+
54+
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${FOUNDATION_LIBRARY})
55+
56+
add_definitions("-DCORE_AUDIO")
57+
add_definitions("-Wno-gnu-zero-variadic-macro-arguments -Wno-four-char-constants -Wno-nullability-extension")
3858
endif()
3959

60+
file( GLOB TEXT_TO_SPEECH_SOURCE "source/text-to-speech/*.cpp" )
61+
4062
if(MSVC)
4163
source_group("Header Files\\aws\\text-to-speech" FILES ${TEXT_TO_SPEECH_HEADERS})
4264
source_group("Header Files\\aws\\text-to-speech\\windows" FILES ${TEXT_TO_SPEECH_PLATFORM_HEADERS})
@@ -69,43 +91,6 @@ if(USE_WINDOWS_DLL_SEMANTICS AND BUILD_SHARED_LIBS)
6991
add_definitions("-DAWS_TEXT_TO_SPEECH_EXPORTS")
7092
endif()
7193

72-
if(PLATFORM_WINDOWS)
73-
add_definitions("-DWAVE_OUT")
74-
set(PLATFORM_LIBS ${PLATFORM_LIBS} Winmm)
75-
endif()
76-
77-
if(HAVE_PULSE)
78-
message(STATUS "Pulse audio header files have been detected, included pulse audio as a possible sound driver implementation.")
79-
add_definitions("-DPULSE")
80-
set(PLATFORM_LIBS ${PLATFORM_LIBS} pulse-simple)
81-
elseif(PLATFORM_LINUX)
82-
message(WARNING "We've detected that you are building on linux, but the header files for pulseaudio are not available.\
83-
If you are providing your own audio implementation or you will not be using the text-to-speech library, this is fine.\
84-
However, if you are not providing your own implemenation and you want to use text-to-speech, you need to install the dev files for pulseudio.\
85-
e.g. apt-get install libpulse-dev or yum install pulseaudio-libs-devel. Currently, no audio implementation will be built into this library.")
86-
endif()
87-
88-
if(PLATFORM_APPLE)
89-
find_library(COREAUDIO_LIBRARY CoreAudio)
90-
find_path(COREAUDIO_INCLUDE_DIR CoreAudioTypes.h)
91-
92-
include_directories(${COREAUDIO_INCLUDE_DIR})
93-
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${COREAUDIO_LIBRARY})
94-
95-
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
96-
find_path(AUDIOTOOLBOX_INCLUDE_DIR AudioQueue.h)
97-
98-
include_directories(${AUDIOTOOLBOX_INCLUDE_DIR})
99-
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${AUDIOTOOLBOX_LIBRARY})
100-
101-
find_library(FOUNDATION_LIBRARY CoreFoundation)
102-
103-
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${FOUNDATION_LIBRARY})
104-
105-
add_definitions("-DCORE_AUDIO")
106-
add_definitions("-Wno-gnu-zero-variadic-macro-arguments -Wno-four-char-constants -Wno-nullability-extension")
107-
endif()
108-
10994
add_library(${PROJECT_NAME} ${LIBTYPE} ${ALL_TEXT_TO_SPEECH})
11095
add_library(AWS::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
11196

aws-cpp-sdk-text-to-speech/include/aws/text-to-speech/PCMOutputDriver.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ namespace Aws
2424
{
2525
namespace TextToSpeech
2626
{
27+
static const unsigned BIT_WIDTH_16 = 16;
28+
static const unsigned MONO = 1;
29+
static const size_t KHZ_22_5 = 22050;
30+
static const size_t KHZ_16 = 16000;
31+
static const size_t KHZ_8 = 8000;
32+
2733
struct CapabilityInfo
2834
{
29-
CapabilityInfo() : channels(1), sampleRate(16000), sampleWidthBits(16) {}
35+
CapabilityInfo() : channels(MONO), sampleRate(KHZ_16), sampleWidthBits(BIT_WIDTH_16) {}
3036

3137
unsigned channels;
3238
size_t sampleRate;

0 commit comments

Comments
 (0)