示例#1
0
    void handle_reply ( std::string json )
    {
        std::stringstream ss ( json );
        std::vector<std::string> words;        
        std::cout << "rapp::cloud::speechToText JSON:" << json << std::endl;

        try
        {
            boost::property_tree::ptree tree;
            boost::property_tree::read_json( ss, tree );
       
            // JSON response is: { words: [], error: '' } 
            for ( auto child : tree.get_child( "words" ) )
                words.push_back ( child.second.get_value<std::string>() );

            // Check for error response from api.rapp.cloud
            for ( auto child : tree.get_child( "error" ) )
            {
                const std::string value = child.second.get_value<std::string>();
                if ( !value.empty() )
                    std::cerr << "speechToText error: " << value << std::endl;
            }
        }
        catch( boost::property_tree::json_parser::json_parser_error & je )
        {
            std::cerr << "speechToText::handle_reply Error parsing: " << je.filename() 
                      << " on line: " << je.line() << std::endl;
            std::cerr << je.message() << std::endl;
        }
        
        delegate_( words );
    }
示例#2
0
void DelegateToken<ParamTypes...>::Invoke(ParamTypes... Args)
{
  delegate_(Args...);
}
示例#3
0
    void handle_reply ( std::string json )
    {   
        std::stringstream ss ( json );
        std::vector< rapp::object::face > faces;

        try
        {
            boost::property_tree::ptree tree;
            boost::property_tree::read_json( ss, tree );
            for ( auto child : tree.get_child( "faces" ) )
            {
		        std::tuple<float,float,float> up_left;
		        std::tuple<float,float,float> down_right;

                for ( auto iter = child.second.begin(); iter!= child.second.end(); ++iter )
                {
                    if ( iter->first == "up_left_point" )
		            {
			            for ( auto it : iter->second )
			            {
		                   if ( it.first == "x" )
                               std::get<0>( up_left ) = it.second.get_value<float>();

                           else if ( it.first == "y" )
                               std::get<1>( up_left ) = it.second.get_value<float>();

//                         else if ( it.first == "z" )
//                             std::get<2>( up_left ) = it.second.get_value<float>();
			            }
		            }
                    else if ( iter->first == "down_right_point" )
		            {
                        for ( auto it : iter->second )
                        {
                            if ( it.first == "x" )
                                std::get<0>( down_right) = it.second.get_value<float>();

                            else if ( it.first == "y" )
                                std::get<1>( down_right ) = it.second.get_value<float>();

                            //else if ( it.first == "z" )
                            //    std::get<2>( down_right ) = it.second.get_value<float>();
                        }
                    }

                }

                faces.push_back( rapp::object::face( std::get<0>( up_left ),
                                                     std::get<1>( up_left ),
                                                     std::get<2>( up_left ),
                                                     std::get<0>( down_right ),
                                                     std::get<1>( down_right ),
                                                     std::get<2>( down_right ) ) );
            }
        }
        catch ( boost::property_tree::json_parser::json_parser_error & je )
        {
            std::cerr << "faceDetector::handle_reply Error parsing: " << je.filename() 
                      << " on line: " << je.line() << std::endl;
            std::cerr << je.message() << std::endl;
        }
        delegate_( faces );
    }