test_rhino.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022, 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 #include <getopt.h>
19 #include <signal.h>
20 #include <chrono>
21 #include <thread>
22 #include <iostream>
23 
24 #include "../src/rhino_recognizer.h"
25 
26 static struct option long_options[] = {
27  { "model_path", required_argument, NULL, 'm' },
28  { "keyword_path", required_argument, NULL, 'k' },
29  { "access_key", required_argument, NULL, 'a' },
30  { "sensitivity", required_argument, NULL, 's' },
31 };
32 
34 {
35  exit(1);
36 }
37 
38 int main(int argc, char** argv)
39 {
40  signal(SIGINT, interrupt_handler);
41 
43 
44  int c;
45  while ((c = getopt_long(argc, argv, "m:c:a:s:r", long_options, NULL)) != -1)
46  {
47  switch (c)
48  {
49  case 'm':
50  parameters.model_path_ = std::string(optarg);
51  break;
52  case 'c':
53  parameters.context_path_ = std::string(optarg);
54  break;
55  case 't':
56  parameters.sensitivity_ = strtof(optarg, NULL);
57  break;
58  case 'a':
59  parameters.access_key_ = std::string(optarg);
60  break;
61  case 'r':
62  parameters.require_endpoint_ = true;
63  break;
64  default:
65  exit(1);
66  }
67  }
68 
69  if (parameters.model_path_.empty() || parameters.context_path_.empty() || parameters.access_key_.empty())
70  {
71  fprintf(stderr, "Usage : %s -m MODEL_PATH -c CONTEXT_PATH -a ACCESS_KEY [-s SENSTIVITY -r (require endpoint)]\n",
72  argv[0]);
73  exit(1);
74  }
75 
77  recognizer.initialize("/tmp/picovoice_driver/test_rhino", 100.);
78  recognizer.configure(parameters);
79 
80  std::cout << "Configure with parameters " << parameters << std::endl;
81 
82  while (true)
83  {
84  recognizer.recognize();
85  while (recognizer.isRecognizing())
86  {
87  std::this_thread::sleep_for(std::chrono::milliseconds(10));
88  }
89  if (recognizer.getResult().is_understood_)
90  {
91  std::cout << "Result: " << recognizer.getResult() << std::endl;
92  }
93  else
94  {
95  std::cout << "--" << std::endl;
96  }
97  }
98 
99  return 0;
100 }
interrupt_handler
void interrupt_handler(int)
Definition: test_rhino.cpp:33
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
main
int main(int argc, char **argv)
Definition: test_rhino.cpp:38
picovoice_driver::RhinoRecognizer::configure
void configure(const RhinoRecognizerData::Parameters &parameters) override
Definition: rhino_recognizer.cpp:60
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
long_options
static struct option long_options[]
Definition: test_rhino.cpp:26
picovoice_driver::RecognizerData::Parameters::model_path_
std::string model_path_
model_path_ Path to the Picovoice model parameters
Definition: recognizer.h:38
picovoice_driver::RhinoRecognizer::getResult
RhinoRecognizerData::Result getResult() override
getResult Get the recognition result
Definition: rhino_recognizer.cpp:110
picovoice_driver::RhinoRecognizer
Definition: rhino_recognizer.h:87
picovoice_driver::RhinoRecognizerData::Parameters
Definition: rhino_recognizer.h:34
picovoice_driver::Recognizer::isRecognizing
bool isRecognizing()
isRecognizing Whether the recognize method is running
Definition: recognizer.cpp:199
picovoice_driver::RhinoRecognizerData::Result::is_understood_
bool is_understood_
is_understood_ Whether the recognizer understood an intent
Definition: rhino_recognizer.h:62
python.test_porcupine.argv
argv
Definition: test_porcupine.py:158
picovoice_driver::Recognizer::recognize
void recognize()
recognize Recognize something from an audio input stream
Definition: recognizer.cpp:164
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::RecognizerData::Parameters::access_key_
std::string access_key_
access_key_ Picovoice access key
Definition: recognizer.h:33
picovoice_driver::Recognizer::initialize
void initialize(const std::string &record_directory, double record_timeout)
initialize Initialize the recognizer
Definition: recognizer.cpp:157


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