RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
set_denoise_profile.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_SET_DENOISE_PROFILE
2 #define RAPP_CLOUD_SET_DENOISE_PROFILE
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
14 {
15 public:
24  const std::shared_ptr<rapp::object::audio> file,
25  const std::string user,
26  const std::string token
27  )
28  : asio_service_http(token)
29  {
30  assert(file);
31  std::string boundary = random_boundary();
32  std::string fname = random_boundary();
33  boost::property_tree::ptree tree;
34  tree.put("user", user);
35  tree.put("audio_source", file->audio_source());
36  tree.put("filename", fname + "." + file->extension());
37  std::stringstream ss;
38  boost::property_tree::write_json(ss, tree, false);
39  post_ = "--" + boundary + "\r\n"
40  + "Content-Disposition: form-data; name=\"json\"\r\n\r\n"
41  + ss.str() + "\r\n";
42  post_ += "--" + boundary + "\r\n"
43  + "Content-Disposition: form-data; name=\"file_uri\";\r\n"
44  + "Content-Transfer-Encoding: binary\r\n\r\n";
45  auto bytes = file->bytearray();
46  post_.insert(post_.end(), bytes.begin(), bytes.end());
47  post_ += "\r\n--" + boundary + "--";
48  header_ = "POST /hop/set_denoise_profile HTTP/1.1\r\n";
49  header_ += "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n\r\n";
50  callback_ = std::bind(&set_denoise_profile::handle_reply, this, std::placeholders::_1);
51  }
52 
53 private:
57  void handle_reply(std::string json)
58  {
59  std::stringstream ss(json);
60  try {
61  boost::property_tree::ptree tree;
62  boost::property_tree::read_json(ss, tree);
63  // Check for error response from api.rapp.cloud
64  for (auto child : tree.get_child("error")) {
65  const std::string value = child.second.get_value<std::string>();
66  if (!value.empty()) {
67  std::cerr << "set_denoise_profile error: " << value << std::endl;
68  }
69  }
70  }
71  catch (boost::property_tree::json_parser::json_parser_error & je) {
72  std::cerr << "set_denoise_profile::handle_reply Error parsing: " << je.filename()
73  << " on line: " << je.line() << std::endl;
74  std::cerr << je.message() << std::endl;
75  }
76  }
77 };
78 }
79 }
80 #endif
std::string header_
Header that will be used.
setting the denoising audio profile for speech recognition
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
std::string post_
Actual post Data.
set_denoise_profile(const std::shared_ptr< rapp::object::audio > file, const std::string user, const std::string token)
set a de-noising profile for a user (for speech recognition)
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
base class for asynchronous http websockets used for connecting to cloud services ...
void handle_reply(std::string json)
handle platform reply (error notifications only)