forked from kPanesar/aws-cpp-sdk-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (66 loc) · 2.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
// AWS Core includes
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/AWSClient.h>
#include <aws/core/utils/Outcome.h>
// AWS DynamoDB includes
#include <aws/dynamodb/DynamoDBClient.h>
#include <aws/dynamodb/model/PutItemRequest.h>
#include <aws/dynamodb/model/PutItemResult.h>
#include <aws/dynamodb/model/ConsumedCapacity.h>
// AWS Polly Includes
#include <aws/polly/PollyClient.h>
#include <aws/polly/model/SynthesizeSpeechRequest.h>
#include <aws/polly/model/SynthesizeSpeechResult.h>
#include <aws/polly/PollyRequest.h>
void TestDynamoDB();
void TestPolly();
using namespace std;
int main(int argc, char *argv[])
{
printf("Hello! This is a quick example on how to use the AWS C++ SDK.\n");
// Initialize the SDK. You'll get a runtime error without this!
Aws::SDKOptions options;
Aws::InitAPI(options);
TestPolly();
return 0;
}
void TestDynamoDB()
{
// Create clients and necessary variables
Aws::DynamoDB::DynamoDBClient dynamoDbClient;
Aws::DynamoDB::Model::PutItemRequest putItemRequest;
Aws::DynamoDB::Model::AttributeValue hashKeyAttribute, valueAttribute;
// Create the query to be sent to the database
putItemRequest.WithTableName("DeveloperTest1");
hashKeyAttribute.SetS("SampleHashKeyValue");
putItemRequest.AddItem("HashKey", hashKeyAttribute);
valueAttribute.SetS("SampleValue");
putItemRequest.AddItem("Name", valueAttribute);
auto putItemOutcome = dynamoDbClient.PutItem(putItemRequest);
// Process the results of the request
if(putItemOutcome.IsSuccess()){
cout << "PutItem Success Using IOPS " << putItemOutcome.GetResult().GetConsumedCapacity().GetTableName() << "\n";
}
else{
cout << "PutItem failed with error " << putItemOutcome.GetError().GetMessage() << "\n";
}
}
void TestPolly()
{
Aws::Polly::PollyClient pollyClient;
Aws::Polly::Model::SynthesizeSpeechRequest speechRequest;
speechRequest.SetVoiceId(Aws::Polly::Model::VoiceId::Kendra);
speechRequest.SetOutputFormat(Aws::Polly::Model::OutputFormat::mp3);
speechRequest.SetText("Hello Dave, how are you doing today?");
auto result = pollyClient.SynthesizeSpeech(speechRequest);
// Aws::IOStream audioStream = result.GetResult().GetAudioStream();
if (result.IsSuccess()){
cout << "Speech synthesis was successfull.";
}
else{
cout << "Speech synthesis failed.\n";
cout << "Error: " << result.GetError().GetMessage();
}
}