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 <atomic>
21 #include <memory>
22 #include <thread>
23 
24 namespace picovoice_driver
25 {
27 {
28  struct Parameters
29  {
33  std::string access_key_;
34 
38  std::string model_path_;
39  };
40 };
41 
46 {
47 public:
53  void initialize(const std::string& record_directory, double record_timeout);
54 
58  void recognize();
59 
63  void preempt();
64 
68  bool isPreempting();
69 
74  bool isRecognizing();
75 
76 protected:
78  {
79  size_t sample_rate_ = 0;
80  size_t frame_length_ = 0;
81  };
82 
84  std::shared_ptr<std::thread> recognize_thread_;
85  void recognizeThread();
87  virtual RecordSettings getRecordSettings() = 0;
88  virtual void recognizeInit() = 0;
89  virtual bool recognizeProcess(int16_t* frames) = 0;
90 
91 private:
92  std::string record_directory_;
94  bool initialized_ = false;
95 
96  std::atomic<bool> preempt_requested_ = ATOMIC_VAR_INIT(false);
97  std::atomic<bool> is_recognizing_ = ATOMIC_VAR_INIT(false);
98 };
99 
100 template <typename RecognizerDataType>
101 class RecognizerT : public Recognizer
102 {
103 public:
111  virtual void configure(const typename RecognizerDataType::Parameters& parameters) = 0;
112 
120  virtual typename RecognizerDataType::Result getResult() = 0;
121 };
122 } // namespace picovoice_driver
picovoice_driver::RecognizerT
Definition: recognizer.h:101
picovoice_driver::RecognizerT::configure
virtual void configure(const typename RecognizerDataType::Parameters &parameters)=0
configure Configure the recognizer
picovoice_driver::Recognizer::recognizeThread
void recognizeThread()
Definition: recognizer.cpp:59
picovoice_driver::Recognizer::recognizeThreadCatchException
void recognizeThreadCatchException()
Definition: recognizer.cpp:145
picovoice_driver::Recognizer::isPreempting
bool isPreempting()
isPreempting Whether a preempt was requested
Definition: recognizer.cpp:190
picovoice_driver::RecognizerData
Definition: recognizer.h:26
picovoice_driver::Recognizer::recognize_thread_exception_string_
std::string recognize_thread_exception_string_
Definition: recognizer.h:83
picovoice_driver::RecognizerData::Parameters::model_path_
std::string model_path_
model_path_ Path to the Picovoice model parameters
Definition: recognizer.h:38
picovoice_driver::Recognizer::recognize_thread_
std::shared_ptr< std::thread > recognize_thread_
Definition: recognizer.h:84
picovoice_driver::Recognizer::is_recognizing_
std::atomic< bool > is_recognizing_
Definition: recognizer.h:97
picovoice_driver
Definition: porcupine_node.cpp:24
picovoice_driver::Recognizer::RecordSettings::frame_length_
size_t frame_length_
Definition: recognizer.h:80
picovoice_driver::Recognizer::getRecordSettings
virtual RecordSettings getRecordSettings()=0
picovoice_driver::Recognizer
The Recognizer class used for recognizing something out of audio data.
Definition: recognizer.h:45
picovoice_driver::Recognizer::recognizeProcess
virtual bool recognizeProcess(int16_t *frames)=0
picovoice_driver::Recognizer::isRecognizing
bool isRecognizing()
isRecognizing Whether the recognize method is running
Definition: recognizer.cpp:199
picovoice_driver::Recognizer::initialized_
bool initialized_
Definition: recognizer.h:94
picovoice_driver::Recognizer::preempt
void preempt()
preempt Preempt the recognition
Definition: recognizer.cpp:181
picovoice_driver::Recognizer::preempt_requested_
std::atomic< bool > preempt_requested_
Definition: recognizer.h:96
picovoice_driver::Recognizer::RecordSettings::sample_rate_
size_t sample_rate_
Definition: recognizer.h:79
picovoice_driver::Recognizer::recognize
void recognize()
recognize Recognize something from an audio input stream
Definition: recognizer.cpp:164
picovoice_driver::Recognizer::record_directory_
std::string record_directory_
Definition: recognizer.h:92
picovoice_driver::Recognizer::RecordSettings
Definition: recognizer.h:77
picovoice_driver::RecognizerT::getResult
virtual RecognizerDataType::Result getResult()=0
getResult Get the recognition result
picovoice_driver::Recognizer::recognizeInit
virtual void recognizeInit()=0
picovoice_driver::RecognizerData::Parameters
Definition: recognizer.h:28
picovoice_driver::RecognizerData::Parameters::access_key_
std::string access_key_
access_key_ Picovoice access key
Definition: recognizer.h:33
picovoice_driver::Recognizer::record_timeout_
double record_timeout_
Definition: recognizer.h:93
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:50