Go to the documentation of this file.
21 #include <yaml-cpp/yaml.h>
35 : key_(key), value_(value)
41 os <<
"{" << kv.
key_ <<
"=" << kv.
value_ <<
"}";
72 throw std::runtime_error(
"Failed to initialize picovoice rhino with parameters " +
toString(parameters) +
": " +
75 const char* context_info =
NULL;
79 throw std::runtime_error(
"Failed to get rhino context info: " + std::string(
pv_status_to_string(status)));
82 auto yaml = YAML::Load(context_info);
85 throw std::runtime_error(
"Context missing key 'context': " + std::string(context_info));
87 if (!yaml[
"context"][
"expressions"])
89 throw std::runtime_error(
"Context missing key 'context/expressions': " + std::string(context_info));
92 std::vector<std::string> context_intents;
93 for (
const auto& kv : yaml[
"context"][
"expressions"])
95 context_intents.push_back(kv.first.as<std::string>());
98 for (
const auto& intent : parameters.
intents_)
100 if (std::find(context_intents.begin(), context_intents.end(), intent) == context_intents.end())
102 throw std::runtime_error(
"Intent '" + intent +
103 "' not available in context. Available intents: " +
toString(context_intents));
131 bool is_finalized =
false;
135 throw std::runtime_error(
"Rhino process failed: " + std::string(
pv_status_to_string(process_status)));
144 throw std::runtime_error(
"Rhino is understood failed: " + std::string(
pv_status_to_string(is_understood_status)));
153 const char* intent_char_array =
NULL;
154 int32_t num_slots = 0;
155 const char** slots =
NULL;
156 const char** values =
NULL;
158 auto intent_status =
pv_rhino_get_intent(rhino_, &intent_char_array, &num_slots, &slots, &values);
161 throw std::runtime_error(
"Rhino get intent failed: " + std::string(
pv_status_to_string(is_understood_status)));
164 std::string intent(intent_char_array);
165 if (!intents_.empty() && std::find(intents_.begin(), intents_.end(), std::string(intent)) == intents_.end())
171 result_.is_understood_ = is_understood;
172 result_.intent_ = intent;
173 for (int32_t i = 0; i < num_slots; ++i)
175 result_.slots_.emplace_back(std::string(slots[i]), std::string(values[i]));
double sensitivity_
sensitivity_ Recognizer sensitivity
PV_API pv_status_t pv_rhino_get_intent(const pv_rhino_t *object, const char **intent, int32_t *num_slots, const char ***slots, const char ***values)
std::ostream & operator<<(std::ostream &os, const PorcupineRecognizerData::Parameters &p)
PV_API pv_status_t pv_rhino_process(pv_rhino_t *object, const int16_t *pcm, bool *is_finalized)
void configure(const RhinoRecognizerData::Parameters ¶meters) override
bool require_endpoint_
require_endpoint_ If true, Rhino requires an endpoint (chunk of silence) before finishing inference.
PV_API int32_t pv_rhino_frame_length(void)
std::string model_path_
model_path_ Path to the Picovoice model parameters
RhinoRecognizerData::Result getResult() override
getResult Get the recognition result
void recognizeInit() override
PV_API void pv_rhino_delete(pv_rhino_t *object)
PV_API pv_status_t pv_rhino_init(const char *access_key, const char *model_path, const char *context_path, float sensitivity, bool require_endpoint, pv_rhino_t **object)
PV_API int32_t pv_sample_rate(void)
std::vector< KeyValue > slots_
slots_ The recognized intent slots
bool recognizeProcess(int16_t *frames) override
PV_API pv_status_t pv_rhino_reset(pv_rhino_t *object)
bool is_understood_
is_understood_ Whether the recognizer understood an intent
PV_API pv_status_t pv_rhino_context_info(const pv_rhino_t *object, const char **context_info)
KeyValue(const std::string &key, const std::string &value)
PV_API pv_status_t pv_rhino_is_understood(const pv_rhino_t *object, bool *is_understood)
std::string context_path_
context_path_ Path to the Picovoice Rhino context.rhn
std::string intent_
intent_ The recognized intent
std::string toString(const T &v)
RecordSettings getRecordSettings() override
const PV_API char * pv_status_to_string(pv_status_t status)
std::vector< std::string > intents_
intents_ Indent candidates, if empty, all returned intents will be considered valid
std::string access_key_
access_key_ Picovoice access key