test_porcupine.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/porcupine_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:k:a:s", long_options, NULL)) != -1)
46  {
47  switch (c)
48  {
49  case 'm':
50  parameters.model_path_ = std::string(optarg);
51  break;
52  case 'k':
53  parameters.keywords_ = { { "keyword", 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  default:
62  exit(1);
63  }
64  }
65 
66  if (parameters.model_path_.empty() || parameters.keywords_.empty() || parameters.access_key_.empty())
67  {
68  fprintf(stderr, "Usage : %s -m MODEL_PATH -k KEYWORD_PATH -a ACCESS_KEY [-s SENSTIVITY]\n", argv[0]);
69  exit(1);
70  }
71 
73  recognizer.initialize("/tmp/picovoice_driver/test_porcupine", 5.);
74  recognizer.configure(parameters);
75 
76  std::cout << "Configure with parameters " << parameters << std::endl;
77 
78  while (true)
79  {
80  recognizer.recognize();
81  while (recognizer.isRecognizing())
82  {
83  std::this_thread::sleep_for(std::chrono::milliseconds(10));
84  }
85  if (recognizer.getResult().is_understood_)
86  {
87  std::cout << "Result: " << recognizer.getResult() << std::endl;
88  }
89  else
90  {
91  std::cout << "--" << std::endl;
92  }
93  }
94 
95  return 0;
96 }
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
picovoice_driver::PorcupineRecognizer
Definition: porcupine_recognizer.h:62
picovoice_driver::RecognizerData::Parameters::model_path_
std::string model_path_
model_path_ Path to the Picovoice model parameters
Definition: recognizer.h:38
long_options
static struct option long_options[]
Definition: test_porcupine.cpp:26
picovoice_driver::PorcupineRecognizer::getResult
PorcupineRecognizerData::Result getResult() override
getResult Get the recognition result
Definition: porcupine_recognizer.cpp:68
interrupt_handler
void interrupt_handler(int)
Definition: test_porcupine.cpp:33
picovoice_driver::Recognizer::isRecognizing
bool isRecognizing()
isRecognizing Whether the recognize method is running
Definition: recognizer.cpp:199
picovoice_driver::PorcupineRecognizerData::Parameters
Definition: porcupine_recognizer.h:33
main
int main(int argc, char **argv)
Definition: test_porcupine.cpp:38
picovoice_driver::PorcupineRecognizerData::Parameters::keywords_
std::map< std::string, std::string > keywords_
keywords_ Map from a keyword names to a keyword.ppn paths
Definition: porcupine_recognizer.h:38
picovoice_driver::PorcupineRecognizer::configure
void configure(const PorcupineRecognizerData::Parameters &parameters) override
Definition: porcupine_recognizer.cpp:46
picovoice_driver::PorcupineRecognizerData::Parameters::sensitivity_
double sensitivity_
sensitivity_ Recognizer sensitivity
Definition: porcupine_recognizer.h:43
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::PorcupineRecognizerData::Result::is_understood_
bool is_understood_
is_understood_ Whether the recognizer understood a keyword
Definition: porcupine_recognizer.h:51
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