1 #ifndef RAPP_CLOUD_SET_DENOISE_PROFILE
2 #define RAPP_CLOUD_SET_DENOISE_PROFILE
24 const std::shared_ptr<rapp::object::audio> file,
25 const std::string user,
26 const std::string token
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());
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"
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";
59 std::stringstream ss(json);
61 boost::property_tree::ptree tree;
62 boost::property_tree::read_json(ss, tree);
64 for (
auto child : tree.get_child(
"error")) {
65 const std::string value = child.second.get_value<std::string>();
67 std::cerr <<
"set_denoise_profile error: " << value << std::endl;
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;
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)