1 #ifndef RAPP_CLOUD_TEXT2SPEECH
2 #define RAPP_CLOUD_TEXT2SPEECH
24 const std::string text,
25 const std::string language,
26 const std::string token,
27 std::function<
void(std::unique_ptr<wav_file>)> callback
31 boost::property_tree::ptree tree;
32 tree.put(
"text", text);
33 tree.put(
"language", language);
35 boost::property_tree::write_json(ss, tree,
false);
37 header_ =
"POST /hop/text_to_speech HTTP/1.1\r\n";
47 std::stringstream ss(json);
48 std::vector<rapp::types::byte> bytearray;
50 boost::property_tree::ptree tree;
51 boost::property_tree::read_json(ss, tree);
54 for (
auto child : tree.get_child(
"payload")) {
56 std::string result = child.second.get_value<std::string>();
57 std::string decoded =
decode64(result);
58 std::copy(decoded.begin(), decoded.end(), std::back_inserter(bytearray));
60 for (
auto child : tree.get_child(
"error")) {
61 const std::string value = child.second.get_value<std::string>();
63 std::cerr <<
"text_to_speech JSON error: " << value << std::endl;
67 catch (boost::property_tree::json_parser::json_parser_error & je) {
68 std::cerr <<
"text_to_speech::handle_reply Error parsing: " << je.filename()
69 <<
" on line: " << je.line() << std::endl;
70 std::cerr << je.message() << std::endl;
73 auto wav = std::unique_ptr<rapp::object::microphone_wav>(
79 std::function<void(std::unique_ptr<wav_file> wav)>
delegate_;
std::string header_
Header that will be used.
std::string decode64(const std::string &val)
decode base64
rapp::object::microphone_wav wav_file
text_to_speech(const std::string text, const std::string language, const std::string token, std::function< void(std::unique_ptr< wav_file >)> callback)
construct handler which will request speech audio from text
std::string post_
Actual post Data.
WAV Single channel 16Khz > Headset audio source.
std::function< void(std::unique_ptr< wav_file > wav)> delegate_
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void handle_reply(std::string json)
handle platform's JSON reply
request speech audio from text
base class for asynchronous http websockets used for connecting to cloud services ...