AlexaClientSDK  1.24.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
KittAiKeyWordDetector.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. 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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_KWD_KITTAI_INCLUDE_KITTAI_KITTAIKEYWORDDETECTOR_H_
17 #define ALEXA_CLIENT_SDK_KWD_KITTAI_INCLUDE_KITTAI_KITTAIKEYWORDDETECTOR_H_
18 
19 #include <atomic>
20 #include <string>
21 #include <thread>
22 #include <unordered_map>
23 #include <unordered_set>
24 
29 
31 #include "KittAi/SnowboyWrapper.h"
32 
33 namespace alexaClientSDK {
34 namespace kwd {
35 
37 public:
43  std::string modelFilePath;
44 
46  std::string keyword;
47 
53  double sensitivity;
54  };
55 
76  static std::unique_ptr<KittAiKeyWordDetector> create(
77  std::shared_ptr<avsCommon::avs::AudioInputStream> stream,
79  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface>> keyWordObservers,
80  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface>>
81  keyWordDetectorStateObservers,
82  const std::string& resourceFilePath,
83  const std::vector<KittAiConfiguration> kittAiConfigurations,
84  float audioGain,
85  bool applyFrontEnd,
86  std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(20));
87 
91  ~KittAiKeyWordDetector() override;
92 
93 private:
114  std::shared_ptr<avsCommon::avs::AudioInputStream> stream,
115  avsCommon::utils::AudioFormat audioFormat,
116  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface>> keyWordObservers,
117  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface>>
118  keyWordDetectorStateObservers,
119  const std::string& resourceFilePath,
120  const std::vector<KittAiConfiguration> kittAiConfigurations,
121  float audioGain,
122  bool applyFrontEnd,
123  std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(20));
124 
132  bool init(avsCommon::utils::AudioFormat audioFormat);
133 
140  bool isAudioFormatCompatibleWithKittAi(avsCommon::utils::AudioFormat audioFormat);
141 
143  void detectionLoop();
144 
146  std::atomic<bool> m_isShuttingDown;
147 
153  std::unordered_map<unsigned int, std::string> m_detectionResultsToKeyWords;
154 
156  const std::shared_ptr<avsCommon::avs::AudioInputStream> m_stream;
157 
159  std::shared_ptr<avsCommon::avs::AudioInputStream::Reader> m_streamReader;
160 
162  std::thread m_detectionThread;
163 
165  std::unique_ptr<SnowboyWrapper> m_kittAiEngine;
166 
171  const size_t m_maxSamplesPerPush;
172 };
173 
174 } // namespace kwd
175 } // namespace alexaClientSDK
176 
177 #endif // ALEXA_CLIENT_SDK_KWD_KITTAI_INCLUDE_KITTAI_KITTAIKEYWORDDETECTOR_H_
std::string modelFilePath
The path to the keyword model.
Definition: KittAiKeyWordDetector.h:43
~KittAiKeyWordDetector() override
Definition: KittAiKeyWordDetector.cpp:103
std::string keyword
The keyword.
Definition: KittAiKeyWordDetector.h:46
Definition: KittAiKeyWordDetector.h:36
double sensitivity
Definition: KittAiKeyWordDetector.h:53
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::unique_ptr< KittAiKeyWordDetector > create(std::shared_ptr< avsCommon::avs::AudioInputStream > stream, avsCommon::utils::AudioFormat audioFormat, std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordObserverInterface >> keyWordObservers, std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface >> keyWordDetectorStateObservers, const std::string &resourceFilePath, const std::vector< KittAiConfiguration > kittAiConfigurations, float audioGain, bool applyFrontEnd, std::chrono::milliseconds msToPushPerIteration=std::chrono::milliseconds(20))
Definition: KittAiKeyWordDetector.cpp:67
Definition: AbstractKeywordDetector.h:30

AlexaClientSDK 1.24.0 - Copyright 2016-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0