Skip to content

Commit 0bef89f

Browse files
Merge pull request #56 from awslabs/PollyToSpeakers
High-level text-to-speech library using polly
2 parents a8d7208 + 9567cb7 commit 0bef89f

21 files changed

+2066
-17
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"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_project(polly_sample
2+
"Sample driver app for polly app."
3+
aws-cpp-sdk-text-to-speech
4+
aws-cpp-sdk-polly
5+
aws-cpp-sdk-core)
6+
7+
file(GLOB AWS_SAMPLE_SRC
8+
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
9+
)
10+
11+
add_executable(${PROJECT_NAME} ${AWS_SAMPLE_SRC})
12+
13+
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS})
14+
copyDlls(${PROJECT_NAME} ${PROJECT_LIBS})

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
*/
15+
16+
#include <aws/core/Aws.h>
17+
#include <aws/text-to-speech/TextToSpeechManager.h>
18+
#include <iostream>
19+
20+
using namespace Aws::Polly;
21+
using namespace Aws::TextToSpeech;
22+
23+
static const char* ALLOCATION_TAG = "PollySample::Main";
24+
25+
void DriveProgram();
26+
void SelectVoiceAndOutputSound(Aws::TextToSpeech::TextToSpeechManager& manager);
27+
28+
int main()
29+
{
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);
103+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
add_project(aws-cpp-sdk-text-to-speech-tests
2+
"Tests for the AWS text-to-speech C++ SDK"
3+
aws-cpp-sdk-text-to-speech
4+
aws-cpp-sdk-polly
5+
testing-resources
6+
aws-cpp-sdk-core)
7+
8+
# Headers are included in the source so that they show up in Visual Studio.
9+
# They are included elsewhere for consistency.
10+
11+
file(GLOB TEXT_TO_SPEECH_TEST_SRC
12+
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
13+
)
14+
15+
if(MSVC AND BUILD_SHARED_LIBS)
16+
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
17+
endif()
18+
19+
enable_testing()
20+
21+
if(PLATFORM_ANDROID AND BUILD_SHARED_LIBS)
22+
add_library(${PROJECT_NAME} ${LIBTYPE} ${TEXT_TO_SPEECH_TEST_SRC})
23+
else()
24+
add_executable(${PROJECT_NAME} ${TEXT_TO_SPEECH_TEST_SRC})
25+
endif()
26+
27+
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS})
28+
copyDlls(${PROJECT_NAME} ${PROJECT_LIBS})
29+
30+
if(NOT CMAKE_CROSSCOMPILING)
31+
ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME} POST_BUILD COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
32+
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
33+
endif()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
*/
15+
16+
#include <aws/external/gtest.h>
17+
#include <aws/core/Aws.h>
18+
#include <aws/testing/platform/PlatformTesting.h>
19+
20+
int main(int argc, char** argv)
21+
{
22+
Aws::SDKOptions options;
23+
24+
Aws::Testing::InitPlatformTest(options);
25+
26+
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
27+
Aws::InitAPI(options);
28+
::testing::InitGoogleTest(&argc, argv);
29+
int exitCode = RUN_ALL_TESTS();
30+
Aws::ShutdownAPI(options);
31+
32+
Aws::Testing::ShutdownPlatformTest(options);
33+
return exitCode;
34+
}
35+
36+
37+
38+

0 commit comments

Comments
 (0)