rhino_recognizer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021, Rein Appeldoorn
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #pragma once
19 
20 #include <map>
21 #include <ostream>
22 #include <picovoice.h>
23 #include <pv_rhino.h>
24 #include <string>
25 #include <vector>
26 
27 #include "./recognizer.h"
28 #include "./util.h"
29 
30 namespace picovoice_driver
31 {
33 {
35  {
39  std::string context_path_;
40 
44  std::vector<std::string> intents_;
45 
49  bool require_endpoint_ = false;
50 
54  double sensitivity_ = 0.5;
55  };
56 
57  struct Result
58  {
62  bool is_understood_ = false;
63 
67  std::string intent_;
68 
69  struct KeyValue
70  {
71  KeyValue(const std::string& key, const std::string& value);
72 
73  std::string key_;
74  std::string value_;
75  };
76 
80  std::vector<KeyValue> slots_;
81  };
82 };
83 std::ostream& operator<<(std::ostream& os, const RhinoRecognizerData::Parameters& p);
84 std::ostream& operator<<(std::ostream& os, const RhinoRecognizerData::Result::KeyValue& kv);
85 std::ostream& operator<<(std::ostream& os, const RhinoRecognizerData::Result& r);
86 
87 class RhinoRecognizer : public RecognizerT<RhinoRecognizerData>
88 {
89 public:
91 
92  void configure(const RhinoRecognizerData::Parameters& parameters) override;
94 
95 private:
97  void recognizeInit() override;
98 
99  bool recognizeProcess(int16_t* frames) override;
100 
101  std::vector<std::string> intents_;
104 };
105 } // namespace picovoice_driver
picovoice_driver::RhinoRecognizerData::Result
Definition: rhino_recognizer.h:57
picovoice_driver::RecognizerT
Definition: recognizer.h:101
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
picovoice_driver::RhinoRecognizerData::Parameters::sensitivity_
double sensitivity_
sensitivity_ Recognizer sensitivity
Definition: rhino_recognizer.h:54
picovoice_driver::RhinoRecognizer::rhino_
pv_rhino_t * rhino_
Definition: rhino_recognizer.h:103
picovoice_driver::operator<<
std::ostream & operator<<(std::ostream &os, const PorcupineRecognizerData::Parameters &p)
Definition: porcupine_recognizer.cpp:25
picovoice_driver::RhinoRecognizerData
Definition: rhino_recognizer.h:32
picovoice_driver::RhinoRecognizer::configure
void configure(const RhinoRecognizerData::Parameters &parameters) override
Definition: rhino_recognizer.cpp:60
recognizer.h
picovoice_driver::RhinoRecognizerData::Result::KeyValue::value_
std::string value_
Definition: rhino_recognizer.h:74
picovoice_driver::RhinoRecognizerData::Parameters::require_endpoint_
bool require_endpoint_
require_endpoint_ If true, Rhino requires an endpoint (chunk of silence) before finishing inference.
Definition: rhino_recognizer.h:49
picovoice_driver::RhinoRecognizer::getResult
RhinoRecognizerData::Result getResult() override
getResult Get the recognition result
Definition: rhino_recognizer.cpp:110
picovoice_driver::RhinoRecognizer::recognizeInit
void recognizeInit() override
Definition: rhino_recognizer.cpp:123
picovoice_driver::RhinoRecognizer
Definition: rhino_recognizer.h:87
picovoice_driver::RhinoRecognizerData::Parameters
Definition: rhino_recognizer.h:34
picovoice_driver
Definition: porcupine_node.cpp:24
picovoice_driver::RhinoRecognizer::result_
RhinoRecognizerData::Result result_
Definition: rhino_recognizer.h:102
picovoice_driver::RhinoRecognizer::intents_
std::vector< std::string > intents_
Definition: rhino_recognizer.h:101
picovoice_driver::RhinoRecognizerData::Result::slots_
std::vector< KeyValue > slots_
slots_ The recognized intent slots
Definition: rhino_recognizer.h:80
picovoice_driver::RhinoRecognizer::recognizeProcess
bool recognizeProcess(int16_t *frames) override
Definition: rhino_recognizer.cpp:129
picovoice_driver::RhinoRecognizerData::Result::is_understood_
bool is_understood_
is_understood_ Whether the recognizer understood an intent
Definition: rhino_recognizer.h:62
picovoice_driver::RhinoRecognizerData::Result::KeyValue::KeyValue
KeyValue(const std::string &key, const std::string &value)
Definition: rhino_recognizer.cpp:34
pv_rhino_t
struct pv_rhino pv_rhino_t
Definition: include/pv_rhino.h:34
picovoice_driver::RhinoRecognizer::~RhinoRecognizer
~RhinoRecognizer()
Definition: rhino_recognizer.cpp:52
picovoice_driver::Recognizer::RecordSettings
Definition: recognizer.h:77
picovoice_driver::RhinoRecognizerData::Parameters::context_path_
std::string context_path_
context_path_ Path to the Picovoice Rhino context.rhn
Definition: rhino_recognizer.h:39
picovoice_driver::RhinoRecognizerData::Result::KeyValue
Definition: rhino_recognizer.h:69
picovoice_driver::RhinoRecognizerData::Result::intent_
std::string intent_
intent_ The recognized intent
Definition: rhino_recognizer.h:67
picovoice_driver::RhinoRecognizer::getRecordSettings
RecordSettings getRecordSettings() override
Definition: rhino_recognizer.cpp:115
util.h
picovoice_driver::RhinoRecognizerData::Parameters::intents_
std::vector< std::string > intents_
intents_ Indent candidates, if empty, all returned intents will be considered valid
Definition: rhino_recognizer.h:44
picovoice_driver::RecognizerData::Parameters
Definition: recognizer.h:28
picovoice_driver::RhinoRecognizerData::Result::KeyValue::key_
std::string key_
Definition: rhino_recognizer.h:73


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:50