RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
path_planning.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_PATH_PLANNING
2 #define RAPP_CLOUD_PATH_PLANNING
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
14 {
15 public:
23  const std::string map_name,
24  const std::string robot_type,
25  const std::string algorithm,
26  // TODO: ROS-PoseStampes must be somehow Wrapped/Translated
27  std::function<void(std::unique_ptr<wav_file>)> callback,
28  const std::string token
29  )
30  : asio_service_http(token), delegate_(callback)
31  {
32  boost::property_tree::ptree tree;
33  tree.put("text", text);
34  tree.put("language", language);
35  std::stringstream ss;
36  boost::property_tree::write_json(ss, tree, false);
37  post_ = ss.str();
38  header_ = "POST /hop/text_to_speech HTTP/1.1\r\n";
39  callback_ = std::bind(&text_to_speech::handle_reply, this, std::placeholders::_1);
40  }
41 private:
45  void handle_reply(std::string json)
46  {
47  std::stringstream ss(json);
48  std::vector<rapp::types::byte> bytearray;
49  try {
50  boost::property_tree::ptree tree;
51  boost::property_tree::read_json(ss, tree);
52 
53  // capture audio payload (base64-encoded)
54  for (auto child : tree.get_child("payload")) {
55  // base64-encoded audio
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));
59  }
60  for (auto child : tree.get_child("error")) {
61  const std::string value = child.second.get_value<std::string>();
62  if (!value.empty()) {
63  std::cerr << "text_to_speech JSON error: " << value << std::endl;
64  }
65  }
66  }
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;
71  }
72  // create wav file and move it to the delegate
73  auto wav = std::unique_ptr<rapp::object::microphone_wav>(
74  new rapp::object::microphone_wav(bytearray));
75  delegate_(std::move(wav));
76  }
77 
79  std::function<void(std::unique_ptr<wav_file> wav)> delegate_;
80 };
81 
82 // TODO: path_upload_map
84 {
85 public:
86 
87 private:
88 
89 };
90 }
91 }
92 #endif
std::string header_
Header that will be used.
std::string decode64(const std::string &val)
decode base64
rapp::object::microphone_wav wav_file
std::string post_
Actual post Data.
WAV Single channel 16Khz > Headset audio source.
Definition: audio.hpp:154
plan_path_d2(const std::string map_name, const std::string robot_type, const std::string algorithm, std::function< void(std::unique_ptr< wav_file >)> callback, const std::string token)
void handle_reply(std::string json)
handle platform's JSON reply
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
std::function< void(std::unique_ptr< wav_file > wav)> delegate_
void handle_reply(std::string json)
handle platform's JSON reply
base class for asynchronous http websockets used for connecting to cloud services ...