NUGU SDK Linux  1.7.6
asr_interface.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
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 #ifndef __NUGU_ASR_INTERFACE_H__
18 #define __NUGU_ASR_INTERFACE_H__
19 
20 #include <functional>
21 
23 #include <nugu.h>
24 
25 namespace NuguCapability {
26 
27 using namespace NuguClientKit;
28 
41 #define NUGU_ASR_EPD_TYPE "CLIENT"
42 #define NUGU_ASR_ENCODING "COMPLETE"
43 #define NUGU_SERVER_RESPONSE_TIMEOUT_SEC 10
49 enum class ASRState {
50  IDLE,
52  LISTENING,
53  RECOGNIZING,
54  BUSY
55 };
56 
61 enum class ASRInitiator {
62  WAKE_UP_WORD,
64  TAP,
66  EARSET
67 };
68 
73 enum class ASRError {
78  UNKNOWN
79 };
80 
85 typedef struct _ASRAttribute {
86  std::string model_path;
87  std::string epd_type;
88  std::string asr_encoding;
91 
96 class NUGU_API IASRListener : virtual public ICapabilityListener {
97 public:
98  virtual ~IASRListener() = default;
99 
108  virtual void onState(ASRState state, const std::string& dialog_id, ASRInitiator initiator) = 0;
109 
114  virtual void onNone(const std::string& dialog_id) = 0;
115 
121  virtual void onPartial(const std::string& text, const std::string& dialog_id) = 0;
122 
128  virtual void onComplete(const std::string& text, const std::string& dialog_id) = 0;
129 
136  virtual void onError(ASRError error, const std::string& dialog_id, bool listen_timeout_fail_beep = true) = 0;
137 
142  virtual void onCancel(const std::string& dialog_id) = 0;
143 };
144 
149 class NUGU_API IASRHandler : virtual public ICapabilityInterface {
150 public:
155  using AsrRecognizeCallback = std::function<void(const std::string& dialog_id)>;
156 
157 public:
158  virtual ~IASRHandler() = default;
159 
167  virtual void startRecognition(float power_noise, float power_speech, ASRInitiator initiator = ASRInitiator::TAP, AsrRecognizeCallback callback = nullptr) = 0;
168 
174  virtual void startRecognition(ASRInitiator initiator = ASRInitiator::TAP, AsrRecognizeCallback callback = nullptr) = 0;
175 
180  virtual void stopRecognition(bool cancel = false) = 0;
181 
185  virtual void finishRecognition() = 0;
186 
191  virtual void addListener(IASRListener* listener) = 0;
192 
197  virtual void removeListener(IASRListener* listener) = 0;
198 
203  virtual void setAttribute(ASRAttribute&& attribute) = 0;
204 
209  virtual void setEpdAttribute(EpdAttribute&& attribute) = 0;
210 
216 };
217 
222 } // NuguCapability
223 
224 #endif /* __NUGU_ASR_INTERFACE_H__ */
ASR handler interface.
Definition: asr_interface.hh:149
virtual void stopRecognition(bool cancel=false)=0
Turn off the microphone and stop speech recognition.
virtual void addListener(IASRListener *listener)=0
Add the Listener object.
virtual void finishRecognition()=0
Finish audio recording and request recognition by a user.
virtual void setAttribute(ASRAttribute &&attribute)=0
Set attribute about speech recognition.
virtual EpdAttribute getEpdAttribute()=0
Get EPD attribute.
virtual void startRecognition(ASRInitiator initiator=ASRInitiator::TAP, AsrRecognizeCallback callback=nullptr)=0
Turn on the microphone and start speech recognition.
std::function< void(const std::string &dialog_id)> AsrRecognizeCallback
ASR recognize callback for user request and response mapping.
Definition: asr_interface.hh:155
virtual void removeListener(IASRListener *listener)=0
Remove the Listener object.
virtual void startRecognition(float power_noise, float power_speech, ASRInitiator initiator=ASRInitiator::TAP, AsrRecognizeCallback callback=nullptr)=0
Turn on the microphone and start speech recognition (support multi-wakeup)
virtual void setEpdAttribute(EpdAttribute &&attribute)=0
Set EPD attribute.
ASR listener interface.
Definition: asr_interface.hh:96
virtual void onError(ASRError error, const std::string &dialog_id, bool listen_timeout_fail_beep=true)=0
Report an error occurred during speech recognition to the user.
virtual void onPartial(const std::string &text, const std::string &dialog_id)=0
The result of recognizing the user's speech in real time.
virtual void onNone(const std::string &dialog_id)=0
No speech recognition results.
virtual void onComplete(const std::string &text, const std::string &dialog_id)=0
Speech recognition results which are reported naturally in situations based on the entire speech.
virtual void onState(ASRState state, const std::string &dialog_id, ASRInitiator initiator)=0
Report to the user asr state changed.
virtual void onCancel(const std::string &dialog_id)=0
Speech recognition is canceled.
capability interface
Definition: capability_interface.hh:82
capability listener interface
Definition: capability_interface.hh:60
ASRInitiator
ASR initiator list.
Definition: asr_interface.hh:61
struct NuguCapability::_ASRAttribute ASRAttribute
Attributes for setting ASR options.
ASRError
ASR error list.
Definition: asr_interface.hh:73
ASRState
ASR state list.
Definition: asr_interface.hh:49
Attributes for setting ASR options.
Definition: asr_interface.hh:85
int response_timeout
Definition: asr_interface.hh:89
std::string asr_encoding
Definition: asr_interface.hh:88
std::string epd_type
Definition: asr_interface.hh:87
std::string model_path
Definition: asr_interface.hh:86
Attributes about epd.
Definition: speech_recognizer_interface.hh:53