AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SensoryKeywordDetector.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 ACSDKSENSORYADAPTER_SENSORY_SENSORYKEYWORDDETECTOR_H_
17 #define ACSDKSENSORYADAPTER_SENSORY_SENSORYKEYWORDDETECTOR_H_
18 
19 #include <atomic>
20 #include <string>
21 #include <thread>
22 #include <unordered_set>
23 
31 
32 #include "snsr.h"
33 
34 namespace alexaClientSDK {
35 namespace kwd {
36 
37 using namespace avsCommon;
38 using namespace avsCommon::avs;
39 using namespace avsCommon::sdkInterfaces;
40 
42 public:
60  static std::unique_ptr<SensoryKeywordDetector> create(
61  const std::shared_ptr<AudioInputStream> stream,
62  const std::shared_ptr<avsCommon::utils::AudioFormat>& audioFormat,
63  std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keyWordNotifier,
64  std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> KeyWordDetectorStateNotifier,
65  const std::string& modelFilePath,
66  std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(10));
67 
86  static std::unique_ptr<SensoryKeywordDetector> create(
87  const std::shared_ptr<AudioInputStream> stream,
89  std::unordered_set<std::shared_ptr<KeyWordObserverInterface>> keyWordObservers,
90  std::unordered_set<std::shared_ptr<KeyWordDetectorStateObserverInterface>> keyWordDetectorStateObservers,
91  const std::string& modelFilePath,
92  std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(10));
93 
97  ~SensoryKeywordDetector() override;
98 
99 private:
115  std::shared_ptr<AudioInputStream> stream,
116  const std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keywordNotifier,
117  const std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> KeywordDetectorStateNotifier,
118  avsCommon::utils::AudioFormat audioFormat,
119  std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(10));
120 
128  bool init(const std::string& modelFilePath);
129 
137  bool setUpRuntimeSettings(SnsrSession* session);
138 
140  void detectionLoop();
141 
150  static SnsrRC keyWordDetectedCallback(SnsrSession s, const char* key, void* userData);
151 
153  std::atomic<bool> m_isShuttingDown;
154 
156  const std::shared_ptr<avsCommon::avs::AudioInputStream> m_stream;
157 
159  std::shared_ptr<avsCommon::avs::AudioInputStream::Reader> m_streamReader;
160 
165  avsCommon::avs::AudioInputStream::Index m_beginIndexOfStreamReader;
166 
168  std::thread m_detectionThread;
169 
171  SnsrSession m_session;
172 
177  const size_t m_maxSamplesPerPush;
178 };
179 
180 } // namespace kwd
181 } // namespace alexaClientSDK
182 
183 #endif // ACSDKSENSORYADAPTER_SENSORY_SENSORYKEYWORDDETECTOR_H_
avsCommon::utils::Optional< InputControllerFactoryInterfaces > create(const std::shared_ptr< acsdkInputControllerInterfaces::InputControllerHandlerInterface > &handler, const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionSender)
Definition: InputControllerFactory.cpp:24
Index
Index used for setting access.
Definition: StateReportGeneratorTest.cpp:41
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: SensoryKeywordDetector.h:41
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58

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