AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AbstractKeywordDetector.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_INCLUDE_KWD_ABSTRACTKEYWORDDETECTOR_H_
17 #define ALEXA_CLIENT_SDK_KWD_INCLUDE_KWD_ABSTRACTKEYWORDDETECTOR_H_
18 
19 #include <mutex>
20 #include <unordered_set>
21 
26 
27 namespace alexaClientSDK {
28 namespace kwd {
29 
31 public:
37  void addKeyWordObserver(std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface> keyWordObserver);
38 
44  void removeKeyWordObserver(std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface> keyWordObserver);
45 
52  std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface> keyWordDetectorStateObserver);
53 
60  std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface> keyWordDetectorStateObserver);
61 
65  virtual ~AbstractKeywordDetector() = default;
66 
67 protected:
75  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface>> keyWordObservers =
76  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface>>(),
77  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface>>
78  keyWordDetectorStateObservers =
79  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface>>());
80 
91  std::shared_ptr<avsCommon::avs::AudioInputStream> stream,
92  std::string keyword,
95  std::shared_ptr<const std::vector<char>> KWDMetadata = nullptr) const;
96 
104 
116  ssize_t readFromStream(
117  std::shared_ptr<avsCommon::avs::AudioInputStream::Reader> reader,
118  std::shared_ptr<avsCommon::avs::AudioInputStream> stream,
119  void* buf,
120  size_t nWords,
121  std::chrono::milliseconds timeout,
122  bool* errorOccurred);
123 
130  static bool isByteswappingRequired(avsCommon::utils::AudioFormat audioFormat);
131 
132 private:
137  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordObserverInterface>> m_keyWordObservers;
138 
143  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface>>
144  m_keyWordDetectorStateObservers;
145 
147  mutable std::mutex m_keyWordObserversMutex;
148 
150  mutable std::mutex m_keyWordDetectorStateObserversMutex;
151 
157 };
158 
159 } // namespace kwd
160 } // namespace alexaClientSDK
161 
162 #endif // ALEXA_CLIENT_SDK_KWD_INCLUDE_KWD_ABSTRACTKEYWORDDETECTOR_H_
KeyWordDetectorState
Definition: KeyWordDetectorStateObserverInterface.h:32
void removeKeyWordObserver(std::shared_ptr< avsCommon::sdkInterfaces::KeyWordObserverInterface > keyWordObserver)
Definition: AbstractKeywordDetector.cpp:42
AbstractKeywordDetector(std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordObserverInterface >> keyWordObservers=std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordObserverInterface >>(), std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface >> keyWordDetectorStateObservers=std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface >>())
Definition: AbstractKeywordDetector.cpp:59
static bool isByteswappingRequired(avsCommon::utils::AudioFormat audioFormat)
Definition: AbstractKeywordDetector.cpp:140
void notifyKeyWordObservers(std::shared_ptr< avsCommon::avs::AudioInputStream > stream, std::string keyword, avsCommon::avs::AudioInputStream::Index beginIndex, avsCommon::avs::AudioInputStream::Index endIndex, std::shared_ptr< const std::vector< char >> KWDMetadata=nullptr) const
Definition: AbstractKeywordDetector.cpp:67
void addKeyWordObserver(std::shared_ptr< avsCommon::sdkInterfaces::KeyWordObserverInterface > keyWordObserver)
Definition: AbstractKeywordDetector.cpp:37
ssize_t readFromStream(std::shared_ptr< avsCommon::avs::AudioInputStream::Reader > reader, std::shared_ptr< avsCommon::avs::AudioInputStream > stream, void *buf, size_t nWords, std::chrono::milliseconds timeout, bool *errorOccurred)
Definition: AbstractKeywordDetector.cpp:90
Index
Index used for setting access.
Definition: StateReportGeneratorTest.cpp:41
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void removeKeyWordDetectorStateObserver(std::shared_ptr< avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface > keyWordDetectorStateObserver)
Definition: AbstractKeywordDetector.cpp:53
void addKeyWordDetectorStateObserver(std::shared_ptr< avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface > keyWordDetectorStateObserver)
Definition: AbstractKeywordDetector.cpp:47
Definition: AbstractKeywordDetector.h:30
void notifyKeyWordDetectorStateObservers(avsCommon::sdkInterfaces::KeyWordDetectorStateObserverInterface::KeyWordDetectorState state)
Definition: AbstractKeywordDetector.cpp:79

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